我需要调用以下 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对其进行了测试