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 を使用して、そこからメソッドの 1 つを使用できるようにしたいのですが、名前空間、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();
    }
}

アクティビティでボタン クリックとして設定しました。これにより、soapMessage TextView が設定されます。KSOAP2 Exception END_DOCUMENT - XMLPullParserExceptiona-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";

WSDL ファイルの URL ではなく、SOAP エンベロープを予期している URL を指す必要があるためです。

非常に特殊なケースであるため、この情報が他の人にとって役に立たない場合は申し訳ありませんが、私が抱えていた問題は解決しました. 助けてくれてありがとう。

于 2012-09-25T19:34:21.863 に答える
1

XML プル パーサー エラーは、WSDL に問題があることを意味します。または、エンドポイントが SOAP メッセージを WSDL が期待される場所に向けているか、またはその逆である可能性があります。私が最初の XML プル パーサーをデバッグしたとき、それは 3 つのことの組み合わせでした: Android で ksoap2 を使用して SOAP 要求を誤って作成したこと、WS-I 準拠の WSDL を持っていなかったこと、および SOAP アクションを指す場所を混乱させたことです。

それを理解するために(そして私以外に誰も本当に助けてくれませんでした)、これらのリンクを使用しました。(参考までに、Visual Studio Express もダウンロードし、SOAP クライアントをまとめました。短時間で、WSDL に関する WS-I 問題を特定するのに役立ちました)

SourceForge のSoapUIツールを使用する

また、デバッグ中にステップスルーできるように、 ksoap2-andriodのソース コードを添付してください。

コードをステップ実行して調べることができます (F5)。それは大いに役立ちます。

直接的なアドバイスとして、PropertyInfo オブジェクトを使用して Property を設定してみてください...

        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 に答える