2017-04-27 45 views
0

我正在開發一個帶有soap服務的android應用程序。但是,當我添加請求屬性時它不起作用。我錯過了什麼嗎?對象referans沒有設置ksoap2

public class WebServiceCallerImp { 

private static final String METHOD_NAME = "GetForexStocksandIndexesInfo"; 
private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String SOAP_ACTION = "http://tempuri.org/GetForexStocksandIndexesInfo"; 
private static final String URL = "http://mobileexam.veripark.com/mobileforeks/service.asmx"; 


public static String GetForex() { 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    request.addProperty("IsIPAD", "true"); 
    request.addProperty("DeviceID", "test"); 
    request.addProperty("DeviceType", "ipad"); 
    request.addProperty("RequestKey", "%%UmVxdWVzdElzVmFsaWQyNzowNDoyMDE3IDEzOjEy%%"); 
    request.addProperty("Period", "Month"); 


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 


    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    androidHttpTransport.debug = true; 

    try { 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     SoapObject response = (SoapObject) envelope.getResponse(); 
     System.out.println("output: " + response.toString()); 
     return response.toString(); 
    } catch (Exception e) { 
     System.out.println("@@@@: " + e.toString()); 

    } 
    return "null"; 
} 

響應

Object reference not set to an instance of an object. at Denizbank.IpadApplication.Integration.ForexIntegration.StocksandIndexes.GetForexStocksandIndexesInfo(StocksandIndexesRequest req) 

在Denizbank.IpadApplication.Service.Service.GetForexStocksandIndexesInfo(StocksandIndexesRequest請求)

SOAP請求

enter image description here

我在哪裏犯錯?請幫幫我。

+0

我想問題與刪除那一個。因爲你沒有啓動該標記,只把完成標記部分。 –

+0

thanx安迪,但沒有工作 –

+0

看到我的答案它適用於我。我做這件事,它適用於我。 –

回答

0

試試這個我做同樣的代碼,沒有在我的項目中的錯誤。

SoapSerializationEnvelope soapEnvelope = null; 
    soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    new MarshalBase64().register(soapEnvelope); 
    soapEnvelope.implicitTypes = true; 
    soapEnvelope.dotNet = true; 
    SoapPrimitive result = null; 

    soapEnvelope.setOutputSoapObject(request); 

    HttpTransportSE aht = new HttpTransportSE(SERVER_URL, Const.HTTP_TIMEOUT); 
    aht.debug = Const.LOG; 

    try { 
     Log.print("SOAP_ACTION::" + SOAP_ACTION, "SERVER_URL::" + SERVER_URL); 
     Log.print("Request", "" + aht.requestDump); 

     aht.call(SOAP_ACTION, soapEnvelope); 
     Log.print("Response", "" + aht.responseDump); 
     result = (SoapPrimitive) soapEnvelope.getResponse(); 

     Log.print("-----------Request :: ", "" + aht.requestDump); 
     Log.print("=====================FINAL RESPONSE================"); 
     Log.print("RESPONSE :: " + result); 
    } catch (UnknownHostException e) { 
     if (Const.LOG) Log.print("UnknownHostException", "" + e); 
     if (Const.LOG) Log.print("Exception in util", e.getMessage()); 
     soapEnvelope = null; 
    } catch (IOException e) { 
     if (Const.LOG) Log.print("IOException", "" + e); 
     e.printStackTrace(); 
     soapEnvelope = null; 
    } catch (XmlPullParserException e) { 
     if (Const.LOG) Log.print("XmlPullParserException", "" + e); 
     e.printStackTrace(); 
     soapEnvelope = null; 
    } catch (OutOfMemoryError e) { 
     if (Const.LOG) Log.print("OutOfMemoryError", "" + e); 
     e.printStackTrace(); 
     soapEnvelope = null; 
     result = null; 
    } catch (Exception e) { 
     if (Const.LOG) Log.print("Exception", "" + e); 
     Log.print("Utils", e); 
     e.printStackTrace(); 
     soapEnvelope = null; 
    } finally { 
     soapEnvelope = null; 
     request = null; 
     SOAP_ACTION = null; 
     SERVER_URL = null; 
     aht = null; 
    } 

Const.LOG值爲true。

+0

我試過解決方案。但迴應爲空。你能在我的解決方案中使用我的參數進行測試 –

+0

我也試過這個答案,還沒有正確答案。 – Thracian

相關問題