How-To : Silverlight accessing Java SOAP services (Part 2 – No Cross Domain : Tomcat/Eclipse)

The HowTo series demo Silverlight accessing Web Services in various configuration. In this post, we will demonstrate you a SOAP service consumed by a Silverlight client application where the Site of Origin hosts the Web Services. This scenario is categorized as a D2D scenario without cross-domain policy.

The SOAP service Eclipse project and the Silverlight Eclipse project are available as an attachment to this post.

Technical Environment

  • SOAP services are built with the JAX-WS and JAX-B Api and hosted in Tomcat

  • The Silverlight application is also hosted in Tomcat


Because the Site of Origin and the Web Service reside in the same host, no Cross Domain policy is required.

Hosting the Web Service in Tomcat

In case you haven’t done the How-To : Silverlight accessing Java SOAP services (Part 1 – Cross Domain : IIS + Tomcat), you can directly import the SOAP-Sum service Eclipse project into your Eclipse Workspace.


Hosting the Silverlight Application using a Servlet

In the REST way, we showed you how to host a Silverlight Application using a JSP. Now we are going to host a Silverlight application using a Servlet

  • In Eclipse, create a new dynamic web project named Silverlight-SOAP-SumService_NOSSL

  • In WebContent folder, add a folder named ClientBin and copy in the latter, the xap file in the attachment. The Silverlight Application is already configured to access the SOAP service at http://localhost:8080/SOAP-SumService/services/sum?wsdl.

  • Add a Servlet named SilverlightServlet to a package ‘servlet’ and add the following code :

Instance of Silverlight plugin :

private void responseHandler(HttpServletResponse response) throws IOException{
    PrintWriter pw = response.getWriter();
    pw.println("" +
            "<div id=\"silverlightControlHost\">" +
            "    <object data=\"data:application/x-silverlight,\"" +
            "             type=\"application/x-silverlight-2-b2\"" +
            "             width=\"100%\" height=\"100%\">" +
            "       <param name=\"source\" value=\"ClientBin/SOAP-Sum.xap\"/>" +
            "       <param name=\"background\" value=\"white\" />" +
            "       <a href=\"\"" +
            "          style=\'text-decoration: none;\'>' +
            "         <img src=\"\""+
            "              alt=\"Get Microsoft Silverlight\"" +
            "              style=\'border-style: none\'/>' +
            "        </a>" +
            "    </object>" +
            "    <iframe style='visibility:hidden;height:0;width:0;border:0px'>' +
            "</iframe>" +

protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    super.doGet(request, response);

Silverlight will access the SOAP-Sum service without cross-domain


- Ronny Kwon

SOAP-SumService + Silverlight In

Comments (1)

Skip to main content