我正在开发一个带有soap服务的Android应用程序。但是,当我添加请求属性时,它不起作用。我错过了什么吗?
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)
at Denizbank.IpadApplication.Service.Service.GetForexStocksandIndexesInfo(StocksandIndexesRequest request)
肥皂请求
我在哪里犯错误?请帮帮我。
答案 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。