title: Soap Call to http://www.w3schools.com/webservices/tempconvert.asmx
body: <p>I have written a soap client to the mentioned service.</p>
  
  <p>But the response I get always shows me an error as answer. I can't really find out where the problem lies. Maybe someone can help me.</p>
  
  <p>Below my code:</p>
  
  <pre><code>public static void main(String[] args) throws SOAPException {
      try {
  
          MessageFactory factory = MessageFactory.newInstance();
          SOAPMessage message = factory.createMessage();
  
          // Get Mime Header
          MimeHeaders mimeHeader = message.getMimeHeaders();
          mimeHeader.addHeader("Host", "www.w3schools.com");
          mimeHeader.addHeader("Content-Type", "text/xml; charset=utf-8");
  
          mimeHeader.addHeader("SOAPAction",
                  "http://tempuri.org/FahrenheitToCelsius");
  
          // Get soap header
          SOAPHeader header = message.getSOAPHeader();
  
          // Enter data into header
  
          // Get soap body
          SOAPBody body = message.getSOAPBody();
          // Enter data into body
          SOAPElement temp = body.addChildElement("FahrenheitToCelsius", "",
                  "http://tempuri.org");
  
          SOAPElement fahr = temp.addChildElement("Fahrenheit");
          fahr.addTextNode("140");
  
          // print what we are sending
          message.writeTo(System.out);
  
          SOAPConnection connection = SOAPConnectionFactory.newInstance()
                  .createConnection();
          SOAPMessage response = connection.call(message, endpoint);
          connection.close();
  
          System.out.println("");
          System.out.println("---------------");
          response.writeTo(System.out);
  
      } catch (SOAPException ex) {
          ex.printStackTrace();
      } catch (IOException ex) {
          ex.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>This is what I am sending:</p>
  
  <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;SOAP-ENV:Header/&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;FahrenheitToCelsius xmlns="http://tempuri.org"&gt;
              &lt;Fahrenheit&gt;140&lt;/Fahrenheit&gt;
          &lt;/FahrenheitToCelsius&gt;
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>And this is what the service is asking me to send:</p>
  
  <pre><code>POST /webservices/tempconvert.asmx HTTP/1.1
  Host: www.w3schools.com
  Content-Type: text/xml; charset=utf-8
  Content-Length: length
  SOAPAction: "http://tempuri.org/FahrenheitToCelsius"
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;FahrenheitToCelsius xmlns="http://tempuri.org/"&gt;
        &lt;Fahrenheit&gt;string&lt;/Fahrenheit&gt;
      &lt;/FahrenheitToCelsius&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>The method itself works. But the response states an error:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;          
      &lt;soap:Body&gt;
          &lt;FahrenheitToCelsiusResponse xmlns="http://tempuri.org/"&gt;
              &lt;FahrenheitToCelsiusResult&gt;Error&lt;/FahrenheitToCelsiusResult&gt;
          &lt;/FahrenheitToCelsiusResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Description of service can be found here: <a href="http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius" rel="nofollow">http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius</a></p>
  
  <p>So I'm am guessing, that I have an incomplete header. But I don't get it how to set it right.</p>