Background:
I have followed the tutorial at: http://drclawx.wordpress.com/2011/06/24/77/
I only managed to get to the hello(msg) method to work by using:
String NAMESPACE = "http://tempuri.org/" // instead of tempuri.org (no slash)
private static final int SOAP_VERSION = SoapEnvelope.VER11;
However for the regular helloWorld I get the following and I really have no idea why...
org.xmlpull.v1.XmlPullParserException:unexpected type(position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@40570bf8
I have also used: android-ws-client 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.
So I tried to start using ksoap2-android...
I have also spent a lot of time on stack overflow trying to find links to tutorials and other suggestions.
Problem:
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).
Please take a look at the following WSDL file:
This wsdl file is located at: http://bcgdev4.bcg.local:12970 (You will not be able to load the link above, so please refer to the wsdl below):
<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">
<wsdl:import namespace="http://tempuri.org/" location="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0"/>
<wsdl:types/>
<wsdl:service name="Commandor">
<wsdl:port name="NetTcpBinding_ICommands" binding="i0:NetTcpBinding_ICommands">
<soap12:address location="net.tcp://bcgdev4:11970/"/>
<wsa10:EndpointReference>
<wsa10:Address>net.tcp://bcgdev4:11970/</wsa10:Address>
<Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<Spn>host/BCGDEV4.BCG.local</Spn>
</Identity>
</wsa10:EndpointReference>
</wsdl:port>
<wsdl:port name="BasicHttpBinding_ICommands" binding="i0:BasicHttpBinding_ICommands">
<soap:address location="http://bcgdev4.bcg.local:13970/mobile"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Right after where the first tag ends- you will see:
<wsdl:import namespace="http://tempuri.org/" location="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0"/>
At http://bcgdev4.bcg.local:12970/?wsdl=wsdl0 - you will get the following wsdl definition:
You won't have access to this either, so please look below:
I want to access the method RunCommandMobile which takes a string and returns a string.
<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/">
<wsp:Policy wsu:Id="NetTcpBinding_ICommands_policy">
<wsp:ExactlyOne>
<wsp:All>
<msb:BinaryEncoding xmlns:msb="http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"/>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<msf:WindowsTransportSecurity xmlns:msf="http://schemas.microsoft.com/ws/2006/05/framing/policy">
<msf:ProtectionLevel>EncryptAndSign</msf:ProtectionLevel>
</msf:WindowsTransportSecurity>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<msf:Streamed xmlns:msf="http://schemas.microsoft.com/ws/2006/05/framing/policy"/>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://bcgdev4.bcg.local:12970/?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://bcgdev4.bcg.local:12970/?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ICommands_RunCommand_InputMessage">
<wsdl:part name="parameters" element="tns:RunCommand"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommand_OutputMessage">
<wsdl:part name="parameters" element="tns:RunCommandResponse"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommandCompress_InputMessage">
<wsdl:part name="parameters" element="tns:RunCommandCompress"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommandCompress_OutputMessage">
<wsdl:part name="parameters" element="tns:RunCommandCompressResponse"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommandMobile_InputMessage">
<wsdl:part name="parameters" element="tns:RunCommandMobile"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommandMobile_OutputMessage">
<wsdl:part name="parameters" element="tns:RunCommandMobileResponse"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommandMobileCompress_InputMessage">
<wsdl:part name="parameters" element="tns:RunCommandMobileCompress"/>
</wsdl:message>
<wsdl:message name="ICommands_RunCommandMobileCompress_OutputMessage">
<wsdl:part name="parameters" element="tns:RunCommandMobileCompressResponse"/>
</wsdl:message>
<wsdl:portType name="ICommands">
<wsdl:operation name="RunCommand">
<wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommand" message="tns:ICommands_RunCommand_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandResponse" message="tns:ICommands_RunCommand_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="RunCommandCompress">
<wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommandCompress" message="tns:ICommands_RunCommandCompress_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandCompressResponse" message="tns:ICommands_RunCommandCompress_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="RunCommandMobile">
<wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommandMobile" message="tns:ICommands_RunCommandMobile_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandMobileResponse" message="tns:ICommands_RunCommandMobile_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="RunCommandMobileCompress">
<wsdl:input wsaw:Action="http://tempuri.org/ICommands/RunCommandMobileCompress" message="tns:ICommands_RunCommandMobileCompress_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICommands/RunCommandMobileCompressResponse" message="tns:ICommands_RunCommandMobileCompress_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="NetTcpBinding_ICommands" type="tns:ICommands">
<wsp:PolicyReference URI="#NetTcpBinding_ICommands_policy"/>
<soap12:binding transport="http://schemas.microsoft.com/soap/tcp"/>
<wsdl:operation name="RunCommand">
<soap12:operation soapAction="http://tempuri.org/ICommands/RunCommand" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RunCommandCompress">
<soap12:operation soapAction="http://tempuri.org/ICommands/RunCommandCompress" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RunCommandMobile">
<soap12:operation soapAction="http://tempuri.org/ICommands/RunCommandMobile" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RunCommandMobileCompress">
<soap12:operation soapAction="http://tempuri.org/ICommands/RunCommandMobileCompress" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="BasicHttpBinding_ICommands" type="tns:ICommands">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RunCommand">
<soap:operation soapAction="http://tempuri.org/ICommands/RunCommand" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RunCommandCompress">
<soap:operation soapAction="http://tempuri.org/ICommands/RunCommandCompress" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RunCommandMobile">
<soap:operation soapAction="http://tempuri.org/ICommands/RunCommandMobile" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RunCommandMobileCompress">
<soap:operation soapAction="http://tempuri.org/ICommands/RunCommandMobileCompress" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
Question:
Using KSoap2-Android: How would I call RunCommandMobile using the webservice? At the moment I have the following and it can't be right:
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;
and here is the code snippet for calling the method:
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();
}
}
I've set it up as a button click in my Activity - that sets the soapMessage TextView.
I just get an Exception END_DOCUMENT - XMLPullParserExceptiona
and since KSOAP2-Android is a jar, I have no way of "seeing" of seeing the actual XML.
Figured out the source of my problem: Everything was correct except this line -
private static final String URL = "http://bcgdev4.bcg.local:12970/?wsdl=wsdl0";
This needs to be:
private static final String URL = "http://bcgdev4.bcg.local:13970/mobile";
Because it needs to point to the URL that is expecting the soap Envelope and not the WSDL file url.
I'm sorry if this information is not of use to anyone else, since its a very specific case, but it did solve the problem I was having. Thanks for the help.