Tuesday, 3 May 2011

Google App Engine: SOAP Client Using JAX-WS

First step is to be familiarized with the wsimport tool. It is used to generate SOAP client from a WSDL file(alternative to it is to use eclipse WTP). To understand what all arguments this tool can take simply type "wsimport -help" in the console and hit enter. It will show you a list of valid arguments.
-d is used to specify the location for generated output files and -s is used to specify the location for generated source files. Refer screenshot below for the complete list of arguments.

Now its time to generate the SOAP client. Execute the following command along with your WSDL file as mentioned below:
wsimport -d "C:\gae\soap_client\bin" -s "C:\gae\soap_client\src" "http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"

Once the client is generated it will look something like this:

Now here is the code for a sample servlet which calls the web service API:
package jbasics;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.webservicex.Currency;
import net.webservicex.CurrencyConvertor;
import net.webservicex.CurrencyConvertorSoap;

public class ServiceCaller extends HttpServlet {
    private static final long serialVersionUID = 8882886813585460639L;

    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
 String strFromCurrency = req.getParameter("fromCurrency");
 String strToCurrency = req.getParameter("toCurrency");

 Currency fromCurrency = Currency.valueOf(strFromCurrency);
 Currency toCurrency = Currency.valueOf(strToCurrency);

 CurrencyConvertorSoap convertorSOAP = new CurrencyConvertor().getCurrencyConvertorSoap();
 double conversionRate = convertorSOAP.conversionRate(fromCurrency, toCurrency);


Add mapping for this servlet in web.xml:

Once you are done with the changes its time to deploy it to Google App Engine. After it is deployed successfully, test it with the following URL (my app url is ext-app.....you should use yours :)):

Google App Engine fully supports JAX-WS for SOAP clients. So it is same as creating client at any other place. But for creating SOAP server for GAE we need to use certain tricks...will cover in upcoming posts. Stay tuned!


  1. I am getting following exception when I followed the steps from ur post.

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

  2. Are you using the latest version of appengine sdk (appengine-java-sdk-1.6.0.zip)?

    If not you can download from the following loation:


    Also did you try running the application from your local dev environment:


    Let me know if you are still not able to run it. I will share the working project then.

  3. I have published the source code at the following location: