title: How to call a SOAP webservice with a simple String (xml in string format)
body: <p>I have this string representing a XML: </p>
  
  <pre><code>String soapCall="&lt;soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"&gt; &lt;soap:Body xmlns:m="http://www.example.org/stock"&gt; &lt;m:addDownloadParams&gt; &lt;m:idApp&gt;";
  soapCall+=idApp;
  soapCall+="&lt;m:versionApp&gt;";
  soapCall+=versonApp;
  soapCall+="&lt;/m:versionApp&gt; &lt;m:os&gt;Android&lt;/m:os&gt; &lt;/m:addDownloadParams&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt;";
  </code></pre>
  
  <p>And i have this soap webservice: </p>
  
  <pre><code>http://stats.mywebsite.com/ws/adddownload
  </code></pre>
  
  <p>Now, i need to pass that string to that soap webservice on android, but i dont know the way, i know i need to use httpcliente:</p>
  
  <pre><code>HttpClient httpClient = new DefaultHttpClient();
  HttpContext localContext = new BasicHttpContext();
  </code></pre>
  
  <p>but i dont know how to call the soapwebservice with that string.</p>
  
  <p>Anyone haves a code example? i can't find it on google. I dont want to use a library, i need to do it by myself</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT: this is the code now, but it is not working, i get error 500 internal server error:</strong></p>
  
  <pre><code>    public static byte[] addDownloadIntoServer(){
          byte[] result = null;
  
          String SERVER_URL="http://stats.mywebsite.com/ws/server.php";
          String SOAP_ACTION="addDownload";
          String body="&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://stats.mobincube.com/\"&gt;&lt;SOAP-ENV:Body&gt;&lt;ns1:addDownloadParams&gt;";
      body+="&lt;idApp&gt;" +SectionManager.instance.app_id+"&lt;/idApp&gt;";
      body+="&lt;versionApp&gt;"+SectionManager.instance.app_version+"&lt;/versionApp&gt;";
      body+="&lt;source&gt;android&lt;/source&gt; &lt;os&gt;Android&lt;/os&gt; &lt;/ns1:addDownloadParams&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;";
  
          HttpParams httpParameters = new BasicHttpParams();
          // Set the timeout in milliseconds until a connection is established.
          int timeoutConnection = 15000;
          HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
          // Set the default socket timeout (SO_TIMEOUT)
          // in milliseconds which is the timeout for waiting for data.
          int timeoutSocket = 35000;
          HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
  
          DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
  
          /*
          * httpclient.getCredentialsProvider().setCredentials( new
          * AuthScope("os.icloud.com", 80, null, "Digest"), new
          * UsernamePasswordCredentials(username, password));
          */
          HttpPost httppost = new HttpPost(SERVER_URL );
          httppost.setHeader("soapaction", SOAP_ACTION);
          httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
  
          System.out.println("executing request" + httppost.getRequestLine());
          //now create a soap request message as follows:
          final StringBuffer soap = new StringBuffer();
          soap.append("\n");
          soap.append("");
          // this is a sample data..you have create your own required data  BEGIN
          soap.append(" \n");
          soap.append(" \n");
          soap.append("" + body);
          soap.append(" \n");
          soap.append(" \n");
  
          /* soap.append(body); */
          // END of MEssage Body
          soap.append("");
          Log.i("SOAP Request", ""+soap.toString());
          // END of full SOAP request  message
          try {
              HttpEntity entity = new StringEntity(soap.toString(),HTTP.UTF_8);
              httppost.setEntity(entity); 
              HttpResponse response = httpclient.execute(httppost);// calling server
              HttpEntity r_entity = response.getEntity();  //get response
              Log.i("Reponse Header", "Begin...");          // response headers
              Log.i("Reponse Header", "StatusLine:"+response.getStatusLine());
              Header[] headers = response.getAllHeaders();
              for(Header h:headers)
                  Log.i("Reponse Header",h.getName() + ": " + h.getValue());
  
              Log.i("Reponse Header", "END...");
              if (r_entity != null) {       
                  result = new byte[(int) r_entity.getContentLength()];  
                  if (r_entity.isStreaming()) {
                      DataInputStream is = new DataInputStream(
                      r_entity.getContent());
                      is.readFully(result);
                  }
              }
          }catch (Exception E) {
              Log.i("Exception While Connecting", ""+E.getMessage());
              E.printStackTrace();
          }
  
          httpclient.getConnectionManager().shutdown(); //shut down the connection
          return result;
      }
  </code></pre>