2013-06-04 76 views
1

我試圖使用https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdlAndroid的ksoap2請求導致HTTP 500

我寫了下面的測試代碼描述Web服務:

private static final String NAMESPACE = "http://swea.riksbank.se/ws"; 
private static final String METHOD_NAME = "getInterestAndExchangeGroupNames"; 
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME; 
private static final String URL = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint"; 

private void testService(){ 

    HttpTransportSE androidHttpTransport = null; 

    try { 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     PropertyInfo groupid = new PropertyInfo(); 
     groupid.setValue(5); 
     groupid.setType(PropertyInfo.INTEGER_CLASS); 
     groupid.setName("groupid"); 

     PropertyInfo languageid = new PropertyInfo(); 
     languageid.setValue("sv"); 
     languageid.setType(PropertyInfo.STRING_CLASS); 
     languageid.setName("languageid"); 

     request.addProperty(groupid); 
     request.addProperty(languageid); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 
     envelope.dotNet = false; 
     envelope.setOutputSoapObject(request); 

     androidHttpTransport = new HttpTransportSE(URL); 
     androidHttpTransport.debug = true; 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     //SoapObject result = (SoapObject)envelope.getResponse(); 
    } 
    catch (Exception e) { 
     Log.e("SOAP_TEST", "========= Request start ========="); 
     Log.e("SOAP_TEST", androidHttpTransport.requestDump); 
     Log.e("SOAP_TEST", "========== Request end =========="); 
     Log.e("SOAP_TEST", "========= Response start ========"); 
     Log.e("SOAP_TEST", androidHttpTransport.responseDump); 
     Log.e("SOAP_TEST", "========== Response end ========="); 

     Log.e("SOAP_TEST", e.toString()); 
     Log.e("SOAP_TEST", e.getMessage()); 
    } 
} 

測試代碼將導致HTTP狀態500

當我檢查請求轉儲請求XML是這樣的:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope"> 
<v:Header /> 
<v:Body> 
    <n0:getInterestAndExchangeGroupNames id="o0" c:root="1" xmlns:n0="http://swea.riksbank.se/ws"> 
     <groupid i:type="d:int">5</groupid> 
     <languageid i:type="d:string">sv</languageid> 
    </n0:getInterestAndExchangeGroupNames> 
    </v:Body> 
</v:Envelope> 

我還引進了WSDL到的soapUI,這將產生以下請求:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://swea.riksbank.se/xsd"> 
    <soap:Header/> 
    <soap:Body> 
     <xsd:getInterestAndExchangeNames> 
     <groupid>5</groupid> 
     <languageid>sv</languageid> 
     </xsd:getInterestAndExchangeNames> 
    </soap:Body> 
</soap:Envelope> 

該請求看起來完全作爲Web服務文檔中的描述,也按預期工作。

那麼做我需要做修復ksoap2要求? (這肥皂的東西對我來說是全新的。)

回答

1

一些更新,現在工作正常後。我工作的測試代碼如下所示:

private static final String NAMESPACE = "http://swea.riksbank.se/xsd"; 
private static final String METHOD_NAME = "getInterestAndExchangeNames"; 
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME; 
private static final String SOAP_URL = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint"; 

private void testService(){ 

    HttpTransportSE androidHttpTransport = null; 

    try { 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     PropertyInfo groupid = new PropertyInfo(); 
     groupid.setValue(5); 
     groupid.setName("groupid"); 
     groupid.setNamespace(""); 

     PropertyInfo languageid = new PropertyInfo(); 
     languageid.setValue("sv"); 
     languageid.setName("languageid"); 
     languageid.setNamespace(""); 

     request.addProperty(groupid); 
     request.addProperty(languageid); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 
     envelope.encodingStyle = SoapEnvelope.ENC; 
     envelope.setAddAdornments(false); 
     envelope.implicitTypes = true; 
     envelope.dotNet = false; 
     envelope.setOutputSoapObject(request); 

     androidHttpTransport = new HttpTransportSE(SOAP_URL); 
     androidHttpTransport.debug = true; 
     androidHttpTransport.call(SOAP_ACTION, envelope); 

     ... 
    }