title: How to setup Android-Web service using KSoap2-android with a complex wsdl file?
body: <p><strong>Background:</strong></p>
  
  <p>I have followed the tutorial at: <a href="http://code.google.com/p/android-ws-client/wiki/androidWSClientHowToV12" rel="nofollow noreferrer">http://drclawx.wordpress.com/2011/06/24/77/</a></p>
  
  <p>I only managed to get to the hello(msg) method to work by using:</p>
  
  <pre><code> String NAMESPACE = "http://tempuri.org/" // instead of tempuri.org (no slash)
   private static final int SOAP_VERSION = SoapEnvelope.VER11;
  </code></pre>
  
  <p>However for the regular helloWorld I get the following and I really have no idea why...</p>
  
  <pre><code> org.xmlpull.v1.XmlPullParserException:unexpected type(position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@40570bf8
  </code></pre>
  
  <p>I have also used: <a href="http://code.google.com/p/android-ws-client/wiki/androidWSClientHowToV12" rel="nofollow noreferrer">android-ws-client</a> and generated stub files, and android libs and tried to use that in my project. I have it all setup but when I run it I get a status 404 being returned and thus an empty response and I don't know why.</p>
  
  <p>So I tried to start using ksoap2-android...</p>
  
  <p>I have also spent a lot of time on stack overflow trying to find links to tutorials and other suggestions. </p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The WSDL file I am working with is fairly complex - I want to be able to use one of the methods from it - using KSoap2-android - but I'm confused as to what to specify as namespace, soap_action, url etc. (My attempt is below the WSDL definitions).</p>
  
  <p>Please take a look at the following WSDL file:</p>
  
  <p>This wsdl file is located at: <a href="http://bcgdev4.bcg.local:12970" rel="nofollow noreferrer">http://bcgdev4.bcg.local:12970</a>
  (You will not be able to load the link above, so please refer to the wsdl below):</p>
  
  <pre><code>&lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://prometheus" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="http://tempuri.org/" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="Commandor" targetNamespace="http://prometheus"&gt;
  &lt;wsdl:import namespace="http://tempuri.org/" location="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0"/&gt;
  &lt;wsdl:types/&gt;
  &lt;wsdl:service name="Commandor"&gt;
  &lt;wsdl:port name="NetTcpBinding_ICommands" binding="i0:NetTcpBinding_ICommands"&gt;
  &lt;soap12:address location="net.tcp://bcgdev4:11970/"/&gt;
  &lt;wsa10:EndpointReference&gt;
  &lt;wsa10:Address&gt;net.tcp://bcgdev4:11970/&lt;/wsa10:Address&gt;
  &lt;Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity"&gt;
  &lt;Spn&gt;host/BCGDEV4.BCG.local&lt;/Spn&gt;
  &lt;/Identity&gt;
  &lt;/wsa10:EndpointReference&gt;
  &lt;/wsdl:port&gt;
  &lt;wsdl:port name="BasicHttpBinding_ICommands" binding="i0:BasicHttpBinding_ICommands"&gt;
  &lt;soap:address location="http://bcgdev4.bcg.local:13970/mobile"/&gt;
  &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>Right after where the first tag ends-  you will see:</p>
  
  <pre><code>&lt;wsdl:import namespace="http://tempuri.org/" location="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0"/&gt;
  </code></pre>
  
  <p>At <a href="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0" rel="nofollow noreferrer">http://bcgdev4.bcg.local:12970/?wsdl=wsdl0</a> - you will get the following wsdl definition:  </p>
  
  <p>You won't have access to this either, so please look below:</p>
  
  <p><em>I want to access the method <strong>RunCommandMobile</strong> which takes a string and returns a string.</em></p>
  
  <pre><code>&lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" targetNamespace="http://tempuri.org/"&gt;
  &lt;wsp:Policy wsu:Id="NetTcpBinding_ICommands_policy"&gt;
  &lt;wsp:ExactlyOne&gt;
  &lt;wsp:All&gt;
  &lt;msb:BinaryEncoding xmlns:msb="http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"/&gt;
  &lt;sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:TransportToken&gt;
  &lt;wsp:Policy&gt;
  &lt;msf:WindowsTransportSecurity xmlns:msf="http://schemas.microsoft.com/ws/2006/05/framing/policy"&gt;
  &lt;msf:ProtectionLevel&gt;EncryptAndSign&lt;/msf:ProtectionLevel&gt;
  &lt;/msf:WindowsTransportSecurity&gt;
  &lt;/wsp:Policy&gt;
  &lt;/sp:TransportToken&gt;
  &lt;sp:AlgorithmSuite&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:Basic256/&gt;
  &lt;/wsp:Policy&gt;
  &lt;/sp:AlgorithmSuite&gt;
  &lt;sp:Layout&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:Strict/&gt;
  &lt;/wsp:Policy&gt;
  &lt;/sp:Layout&gt;
  &lt;/wsp:Policy&gt;
  &lt;/sp:TransportBinding&gt;
  &lt;msf:Streamed xmlns:msf="http://schemas.microsoft.com/ws/2006/05/framing/policy"/&gt;
  &lt;wsaw:UsingAddressing/&gt;
  &lt;/wsp:All&gt;
  &lt;/wsp:ExactlyOne&gt;
  &lt;/wsp:Policy&gt;
  &lt;wsdl:types&gt;
  &lt;xsd:schema targetNamespace="http://tempuri.org/Imports"&gt;
  &lt;xsd:import schemaLocation="http://bcgdev4.bcg.local:12970/?xsd=xsd0" namespace="http://tempuri.org/"/&gt;
  &lt;xsd:import schemaLocation="http://bcgdev4.bcg.local:12970/?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/&gt;
  &lt;/xsd:schema&gt;
  &lt;/wsdl:types&gt;
  &lt;wsdl:message name="ICommands_RunCommand_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommand"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommand_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommandCompress_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandCompress"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommandCompress_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandCompressResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommandMobile_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandMobile"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommandMobile_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandMobileResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommandMobileCompress_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandMobileCompress"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ICommands_RunCommandMobileCompress_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:RunCommandMobileCompressResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name="ICommands"&gt;
  &lt;wsdl:operation name="RunCommand"&gt;
  &lt;wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommand" message="tns:ICommands_RunCommand_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandResponse" message="tns:ICommands_RunCommand_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandCompress"&gt;
  &lt;wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommandCompress" message="tns:ICommands_RunCommandCompress_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandCompressResponse" message="tns:ICommands_RunCommandCompress_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandMobile"&gt;
  &lt;wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommandMobile" message="tns:ICommands_RunCommandMobile_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandMobileResponse" message="tns:ICommands_RunCommandMobile_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandMobileCompress"&gt;
  &lt;wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommandMobileCompress" message="tns:ICommands_RunCommandMobileCompress_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandMobileCompressResponse" message="tns:ICommands_RunCommandMobileCompress_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name="NetTcpBinding_ICommands" type="tns:ICommands"&gt;
  &lt;wsp:PolicyReference URI="#NetTcpBinding_ICommands_policy"/&gt;
  &lt;soap12:binding transport="http://schemas.microsoft.com/soap/tcp"/&gt;
  &lt;wsdl:operation name="RunCommand"&gt;
  &lt;soap12:operation soapAction="http://tempuri.org/ICommands/RunCommand" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandCompress"&gt;
  &lt;soap12:operation soapAction="http://tempuri.org/ICommands/RunCommandCompress" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandMobile"&gt;
  &lt;soap12:operation soapAction="http://tempuri.org/ICommands/RunCommandMobile" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandMobileCompress"&gt;
  &lt;soap12:operation soapAction="http://tempuri.org/ICommands/RunCommandMobileCompress" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap12:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:binding name="BasicHttpBinding_ICommands" type="tns:ICommands"&gt;
  &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  &lt;wsdl:operation name="RunCommand"&gt;
  &lt;soap:operation soapAction="http://tempuri.org/ICommands/RunCommand" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandCompress"&gt;
  &lt;soap:operation soapAction="http://tempuri.org/ICommands/RunCommandCompress" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandMobile"&gt;
  &lt;soap:operation soapAction="http://tempuri.org/ICommands/RunCommandMobile" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="RunCommandMobileCompress"&gt;
  &lt;soap:operation soapAction="http://tempuri.org/ICommands/RunCommandMobileCompress" style="document"/&gt; 
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p><em>Using KSoap2-Android: How would I call RunCommandMobile using the webservice?</em>
  At the moment I have the following and it can't be right:</p>
  
  <pre><code>private static final String METHOD_NAME = "RunCommandMobile";
  private static final String NAMESPACE = "http://tempuri.org/";
  private static final String SOAP_ACTION = "http://tempuri.org/ICommands/RunCommandMobile";
  private static final String URL = "http://bcgdev4.bcg.local:12970/?wsdl=wsdl0";
  private static final int SOAP_VERSION = SoapEnvelope.VER11;
  </code></pre>
  
  <p>and here is the code snippet for calling the method:</p>
  
  <pre><code>private void hello(String message)
  {
      try
      {
          //SoapObject request = new SoapObject(NAMESPACE, "Hello");
          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
          request.addProperty("message", message);
  
          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SOAP_VERSION);
          envelope.dotNet = true;
          envelope.setOutputSoapObject(request);
  
          HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  
          //androidHttpTransport.call("http://tempuri.org/IService1/Hello",envelope);
          androidHttpTransport.call(SOAP_ACTION,envelope);
          Object result = (Object)envelope.getResponse();
  
          String resultData = result.toString();
          soapMessage.setText(resultData);
      } 
      catch (IOException e)
      {
          soapMessage.setText(e.toString());
          e.printStackTrace();
      } 
      catch (XmlPullParserException e)
      {
          soapMessage.setText(e.toString());
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I've set it up as a button click in my Activity - that sets the soapMessage TextView.
  I just get an <code>Exception END_DOCUMENT - XMLPullParserExceptiona</code> and since KSOAP2-Android is a jar, I have no way of "seeing" of seeing the actual XML.</p>