2017-04-27 47 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

相关问题