XapExplorer specifics

documetation covers 2 main areas of how hosted application needs to be written to work with XapExplorer:

1. communication between applications (optional)

2. calling webservices in your application (mandatory)

XapExplorer app communication guide
In order to let your application cooperate fully with XapExplorer environment, U must implement some classes, to be able send/receive commands.

Note: Please keep these classes and functions in your namespace. Data commands are serialized to JSON and don't care of its base (assembly, namespace,...).
please see Support/ClientSupportApi.cs file in source code

Interaction between applications and applications and browser (XapExplorer)
If your application has to respond to commands from other applications, it must register/subscribe to the commands queue, where apps places commands sent to other applications.
Communication between applications is purely event driven and data is exchanged between them using JSON messages.
Event CollectionChanged on ObservableCollection<string> object can be captured by a handler in your application.
Because it is a standard data type from .NET (System.Collections.ObjectModel) U may not inherit from any user defined object.

Join/listen events (hookup your event handler) can be done easily by custom event handler for these app events hooked in your app:
1. GotFocus(), which occurs immediately in your application after load, but only if your application contains an element capable of capturing focus
2. or SizeChanged(), which occurs immediately after inclusion in the application GUI and display.

In the event handler body an application can get 2 following collections which are saved in your UIElementu Resources by XapExplorer during app load:

1. Dictionary<string, string> environment = this.Resources["uhul_eAgri_Environment"], containing the parameters for commands that are required to complete.

2. ObservableCollection<string> commands =  this.Resources["uhul_eAgri_Commands"], that provides Commands. You must perform a registration to this collection CollectionChanged event, such as the following (example c #):

ObservableCollection<string> tmp = this.Resources["uhul_eAgri_Commands"];
tmp.CollectionChanged + = new NotifyCollectionChangedEventHandler (myHandler);

private void myHandler(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
    handle received events ....
}

Now your app is ready to cooperate with the other apps.


Rules for web services in your applications
if your applications uses Web services inside (which is very likely), please do not use the web service default constructor

MojeWebovaSluzba ws = new MojeWebovaSluzba();

but instead use constructor, which excludes the use of file ServiceReferences.ClientConfig.

Important: Your application will be loaded as one of many in the XapExplorer and can not use filesystem in this environment, because it does not exist. It is therefore necessary to call your web service instance using the constructor that is not dependent on mentioned file and specifiy all necessary parameters, such as binding parameters of web services (data message size limit ,...), service endpoint address, etc.

Example VB.NET:
Dim endpointAddress As EndpointAddress = New EndpointAddress(New Uri("http://localhost:4462/Service1.svc")) 
Dim elements = New List(Of BindingElement)()

elements.Add(New BinaryMessageEncodingBindingElement())
elements.Add(New HttpTransportBindingElement())
Dim binding = New CustomBinding(elements)
aa = New ServiceReference1.Service1Client(binding, endpointAddress)

for C#:
EndpointAddress endpointAddress = new EndpointAddress(new Uri("http://localhost:4462/Service1.svc"));
List<BindingElement> elements = new List<BindingElement>();
elements.Add(new BinaryMessageEncodingBindingElement());
elements.Add(new HttpTransportBindingElement());
CustomBinding binding = new CustomBinding(elements);
ServiceReference1.Service1Client aa = new ServiceReference1.Service1Client(binding, endpointAddress);
if https is used there are some additional binding options, see this (VB.NET):
Dim endpointAddress As EndpointAddress = New EndpointAddress(New Uri(Application.Current.Host.Source,"../ServiceMap.svc"))
Dim elements = New List(Of BindingElement)()
elements.Add(New BinaryMessageEncodingBindingElement())
If Application.Current.Host.Source.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase)Then
    elements.Add(New HttpsTransportBindingElement With {.MaxBufferSize = 2147483647, .MaxReceivedMessageSize = 2147483647})
Else
    elements.Add(New HttpTransportBindingElement With {.MaxBufferSize = 2147483647, .MaxReceivedMessageSize = 2147483647})
End If
Dim binding = New CustomBinding(elements)
New ServiceMapClient(binding, endpointAddress)

and same for c#:

Uri targetUri = new Uri("https://localhost:4462/Service1.svc");
EndpointAddress endpointAddress  = new EndpointAddress(targetUri);
List<BindingElement> elements = new List<BindingElement>();
elements.Add(new BinaryMessageEncodingBindingElement());

if(targetUri.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase))
  elements.Add(new HttpsTransportBindingElement() {MaxBufferSize = 2147483647, MaxReceivedMessageSize = 2147483647});
else
  elements.Add(new HttpTransportBindingElement() {MaxBufferSize = 2147483647, MaxReceivedMessageSize = 2147483647});
CustomBinding binding = new CustomBinding(elements);
aa = new ServiceMapClient(binding, endpointAddress);

This will bypass the application of the config file and Web service starts to work completely independently of other files or settings.

Last edited Jan 4, 2012 at 7:48 AM by asida, version 21

Comments

No comments yet.