1

次の Web サービスを呼び出す必要があり、対応する WSDL ファイルがあります。ただし、以下のコードを機能させることができません。

<wsdl:definitions name="ServiceTestService" targetNamespace="http://Rothman.com/">
<wsdl:types>
<schema>
<import namespace="http://Rothman.com/" schemaLocation="http://Rothmanweb.cloudfoundry.com/services/ServiceTestPort?xsd=servicetest_schema1.xsd"/>
</schema>
</wsdl:types>
<wsdl:message name="WhatIsTheAnswerResponse">
    <wsdl:part element="tns:WhatIsTheAnswerResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="WhatIsTheAnswer">
   <wsdl:part element="tns:WhatIsTheAnswer" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="QuestionSEI">
  <wsdl:operation name="WhatIsTheAnswer">
          <wsdl:input message="tns:WhatIsTheAnswer" name="WhatIsTheAnswer"> </wsdl:input>
          <wsdl:output message="tns:WhatIsTheAnswerResponse" name="WhatIsTheAnswerResponse"></wsdl:output>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceTestServiceSoapBinding" type="tns:QuestionSEI">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="WhatIsTheAnswer">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="WhatIsTheAnswer">
  <soap:body use="literal"/>
 </wsdl:input>
 <wsdl:output name="WhatIsTheAnswerResponse"><soap:body use="literal"/>
 </wsdl:output>
 </wsdl:operation>
 </wsdl:binding>
 <wsdl:service name="ServiceTestService">
     <wsdl:port binding="tns:ServiceTestServiceSoapBinding" name="ServiceTestPort">
     <soap:address location="http://Rothmanweb.cloudfoundry.com/services/ServiceTestPort"/>
     </wsdl:port>
</wsdl:service>
</wsdl:definitions>

現在、次のコードがありますが、このサービスに接続するための WSDL からのパラメーターが見つからないようです。このサービスは文字列を入力として受け取り、文字列を出力として返します。次のコード フラグメントがありますが、次の最終的な静的値がわかりません。

    private static final String NAMESPACE = "http://Rothman.com/"; //ok
private static final String METHOD_NAME = "WhatIsTheAnswer"; //ok

private static final String URL = "http://Rothmanweb.cloudfoundry.com/services/ServiceTestPort?wsdl";   
private static final String SOAP_ACTION = "http://Rothman.com/WhatIsTheAnswer";

これらの値は次のように使用されます

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
    SoapSerializationEnvelope envelope =  new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request);
    HttpTransport androidHttpTransport = new HttpTransport(URL);
    try 
    {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
        System.out.println("Received object");
    } catch (Exception e)
    {
        e.printStackTrace();
    }

このコードを使用してこの Web サービスから応答を取得する方法を教えていただければ幸いです。最終変数は正しいですか? soapUI を使用してテストしたため、サービスは適切に動作します

4

1 に答える 1

0

WSDLを含む URL は、Android デバイスから実際にアクセスできるアドレスである必要があります。また、 WSDLにインポートされたXSDスキーマに もアクセスできる必要があります。

Web サービスで入力文字列が必要な場合はPropertyInfo、入力パラメーターとして指定する必要があります。

PropertyInfo methodParam = new PropertyInfo();
methodParam.setName("string");
methodParam.setValue(yourString);
methodParam.setType(PropertyInfo.STRING_CLASS);
Request.addProperty(methodParam);


SoapObject soapObject = new SoapObject(NAMESPACE, methodName);
envelope.setOutputSoapObject(soapObject);
于 2013-02-21T21:03:46.667 に答える