背景:如何使用带有复杂wsdl文件的KSoap2-android来设置Android Web服务?
我已按照教程:http://drclawx.wordpress.com/2011/06/24/77/
我只是设法给你好(MSG)方法通过使用工作:
String NAMESPACE = "http://tempuri.org/" // instead of tempuri.org (no slash)
private static final int SOAP_VERSION = SoapEnvelope.VER11;
不过,对于普通helloWorld我得到以下,我真的不知道为什么...
org.xmlpull.v1.XmlPullParserException:unexpected type(position:END_DOCUMENT [email protected]:0 in [email protected]
我也使用过:android-ws-client并生成存根文件和android库,并试图在我的项目中使用它。我有这一切设置,但是当我运行它时,我得到状态404被返回,因此一个空的回应,我不知道为什么。
于是,我就开始使用ksoap2,机器人......
我也花了很多的时间在堆栈溢出试图找到教程的链接和其他建议。
问题:
我一起工作的WSDL文件是相当复杂的 - 我希望能够使用的从它的方法之一 - 用KSoap2,Android的 - 但我很困惑,什么样指定为名称空间,soap_action,url等(我的尝试低于WSDL定义)。
请看看下面的WSDL文件:
该WSDL文件位于:http://bcgdev4.bcg.local:12970 (你将无法加载上面的链接,请参阅下面的WSDL):
<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>
右后这里ends-你会看到的第一个标签:
<wsdl:import namespace="http://tempuri.org/" location="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0"/>
在http://bcgdev4.bcg.local:12970/?wsdl=wsdl0 - 你会得到日E采用WSDL定义:
这是漫长的和我所以裸 - 你将不能访问此任,所以请看看下面:
我要访问的方法RunCommandMobile这接受一个字符串并返回一个字符串。
<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>
问:
使用KSoap2-安卓:我怎么会叫RunCommandMobile使用WebService?调用该方法
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;
这里是代码片段:
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();
}
}
我已经将它设置为 目前我有以下的,它不可能是正确的按钮单击我的活动 - 设置soapMessage TextView。 我刚刚得到了一个Exception END_DOCUMENT - XMLPullParserExceptiona
,由于KSOAP2-Android是一个jar,所以我无法“看到”看到实际的XML。
任何帮助...非常感谢。
+1的尝试 - 我不需要在最后使用属性信息,它实际上原来是一个简单的错误来解决。无论如何感谢您的帮助! – ryvianstyron
@ user1292233,常见错误(或错误组合)。你需要找到自己的东西......这是对任何有XMLPull分析器错误的人的建议。很高兴你喜欢它。 – Kickaha