0

背景:

我已按照以下教程进行操作: http: //drclawx.wordpress.com/2011/06/24/77/

我只设法使用 hello(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 null@1:0 in java.io.InputStreamReader@40570bf8

我还使用过:android-ws-client和生成的存根文件,以及 android libs 并尝试在我的项目中使用它。我已经设置好了,但是当我运行它时,我得到一个状态 404 被返回,因此一个空响应,我不知道为什么。

所以我尝试开始使用 ksoap2-android ......

我还花了很多时间在堆栈溢出上,试图找到指向教程和其他建议的链接。

问题:

我正在使用的 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>

在第一个标签结束的地方之后——你会看到:

<wsdl:import namespace="http://tempuri.org/" location="http://bcgdev4.bcg.local:12970/?wsdl=wsdl0"/>

http://bcgdev4.bcg.local:12970/?wsdl=wsdl0 - 您将获得以下 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-Android:如何使用 web 服务调用 RunCommandMobile? 目前我有以下内容,这是不对的:

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();
    }
}

我已将其设置为我的 Activity 中的按钮单击 - 设置soapMessage TextView。我只是得到一个Exception END_DOCUMENT - XMLPullParserExceptiona,因为 KSOAP2-Android 是一个 jar,我无法“看到”看到实际的 XML。

4

2 回答 2

2

找出我的问题的根源:除了这一行之外,一切都是正确的 -

private static final String URL = "http://bcgdev4.bcg.local:12970/?wsdl=wsdl0";

这需要是:

 private static final String URL = "http://bcgdev4.bcg.local:13970/mobile";

因为它需要指向期望肥皂信封的 URL,而不是 WSDL 文件 url。

如果此信息对其他人没有用,我很抱歉,因为它是一个非常具体的案例,但它确实解决了我遇到的问题。谢谢您的帮助。

于 2012-09-25T19:34:21.863 回答
1

XML Pull Parser Error 意味着您的 WSDL 存在错误。或者您的端点可能将肥皂消息指向预期 WSDL 的位置,或者相反。当我调试我的第一个 XML Pull 解析器时,它是三件事的组合:在 android 中使用 ksoap2 错误地构建了 soap 请求,没有符合 WS-I 的 WSDL,以及混淆了肥皂动作的指向。

为了弄清楚(除了我之外没有人能真正帮助我)我使用了这些链接。(仅供参考,我还下载了visual studio express并组装了一个soap客户端,只用了很短的时间就帮助我用WSDL隔离了WS-I问题)

使用SourceForge的SoapUI工具

还附上ksoap2-andriod的源代码,以便我可以在调试时逐步完成。

您将能够单步执行代码并检查 (F5)。这很有帮助。

一条直接的建议,尝试使用 PropertyInfo 对象设置您的属性...

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo pi = new PropertyInfo();
        pi.setName("message");
        pi.setValue(message);
        pi.setType(String.class);
        request.addProperty(pi);

我希望这有帮助。

于 2012-09-22T04:31:59.750 回答