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.
- Export it as a WAR in %TOMCAT_INSTALL%/webapps folder
- go to https://localhost:8080/SOAP-SumService/services/sum (assuming that Tomcat is running on port 8080) to access the service.
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 https://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=\"https://go.microsoft.com/fwlink/?LinkID=115261\"" +
" style=\'text-decoration: none;\'>' +
" <img src=\"https://go.microsoft.com/fwlink/?LinkId=108181\""+
" alt=\"Get Microsoft Silverlight\"" +
" style=\'border-style: none\'/>' +
" </a>" +
" </object>" +
" <iframe style='visibility:hidden;height:0;width:0;border:0px'>' +
"</iframe>" +
"</div>");
pw.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
responseHandler(response);
super.doGet(request, response);
}
- Export the project as a WAR file in %TOMCAT_INSTALL%/webapps folder.
- Go to https://localhost:8080/Silverlight-SOAP-SumService_NOSSL/SilverlightServlet (because In the web.xml file located in WebContent/WEB-INF directory, the servlet is configured to handle every requests made on /SilverlightServlet/*)
Silverlight will access the SOAP-Sum service without cross-domain
SOAP-SumService + Silverlight In Tomcat.zip.zip
Comments
- Anonymous
August 28, 2008
PingBack from http://hubsfunnywallpaper.cn/?p=2782