无法从此wsdl中挑选出参数以用于Web服务调用

时间:2013-02-21 08:22:10

标签: android wsdl ksoap2

我需要调用以下webservice并且我有相应的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中找到连接到此服务的参数。 sercvice将一个字符串作为输入并返回一个字符串作为输出。 我有以下代码片段,我不确定以下最终静态值。

    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

测试后,该服务正常工作

1 个答案:

答案 0 :(得分:0)

带有 WSDL 的网址必须是来自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);