title: How to call a soap web service from JQuery
body: <p>I have developed a sample application for calling soap web service from JQuery, but I am facing some problem to finding service. I am using apache cxf 2.2.6 jars.</p>
  
  <blockquote>
    <p>I used this<br>
    <a href="http://www.local-guru.net/blog/2010/1/24/calling-webservices-from-mootools-jquery-or-dojo" rel="nofollow">http://www.local-guru.net/blog/2010/1/24/calling-webservices-from-mootools-jquery-or-dojo</a>
    to create a webservice cal from JQuery</p>
  </blockquote>
  
  <p>this is my interface</p>
  
  <pre><code>package guru.service;
  import javax.jws.WebService;
  import javax.jws.WebParam;
  import javax.xml.ws.RequestWrapper;
  @WebService( targetNamespace = "http://www.local-guru.net/helloService" )
  public interface HelloService {
      @RequestWrapper( targetNamespace="http://www.local-guru.net/helloService" )
      public String hello(@WebParam( name="givenname", targetNamespace="http://www.local-guru.net/helloService"  ) String givenname, @WebParam( name="name", targetNamespace="http://www.local-guru.net/helloService" ) String name );
  }
  </code></pre>
  
  <p>My implementation class is </p>
  
  <pre><code>package guru.service;
  import javax.jws.WebService;
  @WebService( endpointInterface="guru.service.HelloService", serviceName="HelloService", targetNamespace = "http://www.local-guru.net/helloService" )
  public class HelloServiceImpl implements HelloService{
      public String hello( String givenname, String name ) {
          return "Hello " + givenname + " " + name + "!";
      }
  }
  </code></pre>
  
  <p>And My application context </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"&gt;   
      &lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;
      &lt;import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /&gt;
      &lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml" /&gt;           
      &lt;bean id="helloServiceImpl" class="guru.service.HelloServiceImpl" /&gt;    
          &lt;jaxws:endpoint id="helloService" 
          implementor="#helloServiceImpl" address="/helloService"/&gt;        
  &lt;/beans&gt;
  </code></pre>
  
  <p>I can see my WSDl definition by using this URL </p>
  
  <blockquote>
    <p><a href="http://192.168.1.209:8080/sampleWebService/helloService?wsdl" rel="nofollow">http://192.168.1.209:8080/sampleWebService/helloService?wsdl</a></p>
  </blockquote>
  
  <p>Using soapUI 3.6.1 software I created soap request for this service</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://www.local-guru.net/helloService"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;hel:hello&gt;         
           &lt;hel:givenname&gt;MAYA&lt;/hel:givenname&gt;         
           &lt;hel:name&gt;MANI&lt;/hel:name&gt;
        &lt;/hel:hello&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>My Service response is </p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap:Body&gt;
        &lt;ns2:helloResponse xmlns:ns2="http://www.local-guru.net/helloService"&gt;
           &lt;return&gt;Hello MAYA MANI!&lt;/return&gt;
        &lt;/ns2:helloResponse&gt;
     &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>but when I try to call my service using jquery, I get this error </p>
  
  <blockquote>
    <p>WARNING: Interceptor for
    {http://www.local-guru.net/helloService}HelloService has thrown
    exception, unwinding now org.apache.cxf.binding.soap.SoapFault: Error
    reading XMLStreamReader.  at
    org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:230)
      at
    org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60)
      at
    org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
      at
    org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:109)
      at
    org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:98)
      at
    org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:406)
      at
    org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:178)
      at
    org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
      at
    org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
      at
    org.apache.cxf.transport.servlet.AbstractHTTPServlet.doOptions(AbstractHTTPServlet.java:132)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)     at
    org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
      at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at
    org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at
    org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:619) Caused by:
    com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog  at
    [row,col {unknown-source}]: [1,0]     at
    com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:686)
      at
    com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2134)
      at
    com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2040)
      at
    com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
      at
    com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1095)
      at
    org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:122)
      ... 25 more</p>
  </blockquote>
  
  <p>And my html page is </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script src="jquery.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  function callservice() {
      var givenname = $("#givenName").val();
      var name = $("#name").val();
  
      var q ='&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://www.local-guru.net/helloService"&gt;&lt;soapenv:Header/&gt;&lt;soapenv:Body&gt;&lt;hel:hello&gt;&lt;hel:givenname&gt;'+givenname+'&lt;/hel:givenname&gt;&lt;hel:name&gt;'+name+'&lt;/hel:name&gt;&lt;/hel:hello&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;'
             $.ajax({
          url: 'http://192.168.1.209:8080/sampleWebService/helloService/hello',
          data: q,
          type: 'post',
          contentType: 'text/xml; charset="utf-8"',
          success: function(res) {
              $('#result').html(
                  res.getElementsByTagNameNS("http://www.local-guru.net/helloService",
                  "helloResponse")[0].childNodes[0].childNodes[0].nodeValue);
          },
  
      });
  }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form&gt;
          &lt;input type="text" id="givenName"/&gt;
          &lt;input type="text" id="name"/&gt;
          &lt;input type="button" onClick="callservice()"/&gt;
      &lt;/form&gt;
      &lt;div id="result"&gt;result&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Please help me solve this problem.</p>