title: Java: how to create SOAP request?
body: <p>I have a wsdl and xsd files and want to create SOAP request to web server on python. I have never worked with soap before so my question probably simple but I spend the four hours and havn't found the solution. </p>
  
  <p>I try two ways: low level request and KSOAP2 on Android. </p>
  
  <p>wsdl</p>
  
  <pre><code>    &lt;wsdl:message name="&lt;some request&gt;"&gt;
      &lt;wsdl:part element="txh:&lt;some request&gt;" name="parameters"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="&lt;some response&gt;"&gt;
      &lt;wsdl:part element="txh:&lt;some response&gt;" name="parameters"/&gt;
  &lt;/wsdl:message&gt;
  </code></pre>
  
  <p>xsd</p>
  
  <pre><code>    &lt;xs:element name=""&lt;some request&gt;"&gt;
      &lt;xs:annotation&gt;
          &lt;xs:documentation&gt;"&lt;text&gt;"&lt;/xs:documentation&gt;
      &lt;/xs:annotation&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="mode" type="response-mode"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="&lt;some response&gt;"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:annotation&gt;
              &lt;xs:documentation&gt;"&lt;text&gt;"&lt;/xs:documentation&gt;
          &lt;/xs:annotation&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="&lt;text&gt;"/&gt;
              &lt;xs:element name="&lt;another text&gt;" minOccurs="0"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="&lt;name a&gt;" type="xs:int"/&gt;
                          &lt;xs:element name="&lt;name b&gt;" type="xs:int"/&gt;
                          &lt;xs:element name="&lt;name c&gt;" type="xs:int"/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>Code in Android:</p>
  
  <pre><code>private final static String xml = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n" +
                           "&lt;SOAP-ENV:Envelope " +
                           "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                           "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
                           "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                           "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"&gt;" +
                          "&lt;SOAP-ENV:Header&gt;" +
                          "&lt;/SOAP-ENV:Header&gt;" +
                          "&lt;SOAP-ENV:Body xmlns:ns1=\"&lt;namespace&gt;\"&gt;" +
                          "    &lt;xs:element name=\"&lt;request&gt;\"&gt; " +
                          "&lt;xs:annotation&gt;" +
                              "&lt;xs:documentation&gt;"&lt;text&gt;"&lt;/xs:documentation&gt;" +
                          "&lt;/xs:annotation&gt;" +
                          "&lt;xs:complexType&gt;" +
                              "&lt;xs:sequence&gt;" +
                                  "&lt;xs:element name=\""&lt;text&gt;"\" type=\"response-mode\"/&gt;" +
                              "&lt;/xs:sequence&gt;" +
                          "&lt;/xs:complexType&gt;" +
                      "&lt;/xs:element&gt;" +
                          "&lt;/SOAP-ENV:Body&gt;" +
                          "&lt;/SOAP-ENV:Envelope&gt;";
  
  
  
   public Entity execute(final String body) {
      Log.d(TAG, "Start request ");
      Entity result = new Entity();
      AndroidHttpClient client = AndroidHttpClient.newInstance(TAG);
      HttpParams params = client.getParams();
      HttpConnectionParams.setConnectionTimeout(params, 10000);
      HttpConnectionParams.setSoTimeout(params, 15000);
      HttpProtocolParams.setUseExpectContinue(params, true);
  
      HttpPost post = new HttpPost(url);
      post.setParams(params);
      post.setHeader("soapaction", NAMESPACE.concat("/").concat(METHOD));
      post.setHeader("Content-Type", "text/xml; charset-utf8");
      try {
          String request = createRequest(xml);
          HttpEntity entityToRequest = new StringEntity(request);
          post.setEntity(entityToRequest);
          Log.d(TAG, post.toString());
  
          HttpResponse response = client.execute(post);
          final int status = response.getStatusLine().getStatusCode();
          if (HttpStatus.SC_OK == status) {
              HttpEntity entity = response.getEntity();
              String str = EntityUtils.toString(entity);
              Log.d(TAG, str);
          }
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>On this request I get a 500 server code, so I suppose that the issue in my request. Do you think that it is formed well?  </p>