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 (4)

  1. Following TOTD (Tip Of The Day) pattern, I’m starting LOTD (Link Of The Day) series today. These are light-weight entries with generally a single line description and links to other blogs/articles/tips/whitepapers/screencasts/etc. Let’s start with three

  2. bmilenkovic says:

    We are also trying to get Sivlerlight to work with GlassFish, but running into issues.  Dropping clientaccesspolicy.xml in docroot folder makes it accessible at http://localhost:8080/clientaccesspolicy.xml.  However, our services are hosted at http://localhost:9080/services….

    Is there a way to tell Silverlight to look for clientaccesspolicy.xml on a different port than the port that services are provided?