How To: Call Java EE Web Service from Silverlight Client

How To: Call Java EE Web Service from Silverlight Client

Java EE Web Service Silverlight Client I have already posted about How To: Call a Java EE Web Service from a .Net Client, but if Silverlight is the .Net client application that consumes that service, there are several issues you should be aware of.

Only asynchronous operations

When adding a service reference from a Silverlight application to any web service, the generated proxy has only async operations. This means that instead of calling the operation and get the result:

CalculatorServiceClient proxy = new CalculatorServiceClient();

int result = proxy.Add(2, 3);

Console.WriteLine("Calculator Service returned: " + result.ToString());

what you have to do is call the async version of this method, and register to the completed event:

CalculatorServiceClient proxy = new CalculatorServiceClient();

proxy.AddCompleted += proxy_AddCompleted;

proxy.AddAsync(a, b);

and as the implementation of the proxy_AddCompleted method, get the result:

void proxy_AddCompleted(object sender, AddCompletedEventArgs e)

{

    int result = e.Result;
   
    ...

}

Cross Domain Calls

Since the Java service is probably hosted on another domain, calling it is considered as a cross domain access. I have posted about the HTTP 404 error when calling a service from a Silverlight Client across domains, and this solution applies here too.

The thing is that since the Java EE is hosted on another web server than IIS, you should place the clientaccesspolicy.xml file on the root of your domain. On my machine, I have GlassFish V2 installed, and the file should be placed at: C:\Users\guyb\.personalDomain\personalDomain\docroot\ folder.

Hope this helps!

Comments