2013-02-21 22 views
1

我需要調用以下webservice並獲得其相應的WSDL文件。但是,我無法獲得下面的代碼工作。無法從此wsdl中挑選參數以便在webservice調用中使用

<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

回答

0

URL與WSDL必須從Android設備的真正訪問地址。並且還導入了XSD架構WSDL必須是可訪問的。

如果您的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); 
+0

是不是假設是'soapObject.addProperty(methodParam)'。我相信你有一個錯字 – MistyD 2013-02-21 23:58:49

+0

對不起。應該有'Request.addProperty(methodParam);'。看看這個教程http://seesharpgears.blogspot.sk/2010/10/ksoap-android-web-service-tutorial-with.html – misco 2013-02-22 12:13:23

相關問題