title: Spring: WebServiceTransportException: Not Found [404] for very simple WS client
body: <p>I am trying to write a client for publicly exposed service. I only need to pass <strong>raw XML</strong> (as Java string) and view raw response. No binding is required.</p>
  
  <p>Service is publicly exposed here: <a href="http://www.webservicex.net/periodictable" rel="nofollow">http://www.webservicex.net/periodictable</a></p>
  
  <p>I verified that following request XML <strong>works correctly</strong> (via Soap UI):</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;web:GetAtomicWeight&gt;
           &lt;!--Optional:--&gt;
           &lt;web:ElementName&gt;Aluminium&lt;/web:ElementName&gt;
        &lt;/web:GetAtomicWeight&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>I am using Spring's template for WS, Maven dependency here:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.ws&lt;/groupId&gt;
      &lt;artifactId&gt;spring-ws-core&lt;/artifactId&gt;
      &lt;version&gt;2.1.3.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Now, here is my simple "main" application. It just delegates XML string to Spring's <code>WebServiceTemplate</code> and expect to see result in <code>System.out</code>. </p>
  
  <pre><code>package sk.xorty.ws;
  
  import org.springframework.ws.client.core.WebServiceTemplate;
  import org.springframework.ws.soap.client.core.SoapActionCallback;
  import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
  
  import javax.xml.soap.MessageFactory;
  import javax.xml.soap.SOAPConstants;
  import javax.xml.soap.SOAPException;
  import javax.xml.transform.stream.StreamResult;
  import javax.xml.transform.stream.StreamSource;
  import java.io.StringReader;
  
  public class WsTest {
  
      private static final String REQUEST_PERIODIC =
              "&lt;soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://www.webserviceX.NET\"&gt;\n" +
              "   &lt;soap:Header/&gt;\n" +
              "   &lt;soap:Body&gt;\n" +
              "      &lt;web:GetAtomicWeight&gt;\n" +
              "         &lt;web:ElementName&gt;Aluminium&lt;/web:ElementName&gt;\n" +
              "      &lt;/web:GetAtomicWeight&gt;\n" +
              "   &lt;/soap:Body&gt;\n" +
              "&lt;/soap:Envelope&gt;\n";
  
      private static final String URL_PERIODIC = "http://www.webservicex.net/periodictable";
  
      private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
  
      // send to an explicit URI
      public void customSendAndReceive() throws SOAPException {
          MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
          SaajSoapMessageFactory newSoapMessageFactory = new SaajSoapMessageFactory(messageFactory);
          webServiceTemplate.setMessageFactory(newSoapMessageFactory);
  
          StreamSource source = new StreamSource(new StringReader(REQUEST_PERIODIC));
          StreamResult result = new StreamResult(System.out);
          webServiceTemplate.sendSourceAndReceiveToResult(URL_PERIODIC, source,
                  new SoapActionCallback("GetAtomicWeight"), result);
      }
  
      public static void main(String[] args) throws SOAPException {
          new WsTest().customSendAndReceive();
      }
  }
  </code></pre>
  
  <p>Example is runnable (it only needs dependency above in classpath). It throws following error:</p>
  
  <pre><code>INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
  Exception in thread "main" org.springframework.ws.client.WebServiceTransportException: Not Found [404]
      at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:663)
      at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:587)
      at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
      at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
      at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:436)
      at sk.xorty.ws.WsTest.customSendAndReceive(WsTest.java:38)
      at sk.xorty.ws.WsTest.main(WsTest.java:43)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Correct value for request is this one:</p>
  
  <pre><code>private static final String REQUEST_PERIODIC = "&lt;web:GetAtomicWeight xmlns:web=\"http://www.webserviceX.NET\"&gt;\n" +
          "         &lt;!--Optional:--&gt;\n" +
          "         &lt;web:ElementName&gt;Aluminium&lt;/web:ElementName&gt;\n" +
          "      &lt;/web:GetAtomicWeight&gt;";
  </code></pre>