我的应用程序运行在使用Android 4.4.4作为操作系统的Nexus 7 2012 WIFI上。我们用Eclipse编译了应用程序,它运行没有问题。该应用程序使用SOAP向.Net Web服务发送请求。我们在SQL服务器上调用一个基本上从服务器获取日期的存储过程。
但是,在运行使用Android Studio编译的相同应用程序时,Web服务会以Object Reference not set to an instance of an object
错误响应。除了使用gradle构建之外,代码是相同的。
这是SOAP调用:
/**
* Calls the stored proc on the server to return a dataset/SoapObject. This will always run the ProcReader method on the web server.
*
* @param storedProc The Stored Proc to call
* @param params The parameter(s) for the stored proc (pipe seperated for multiple parameters)
* @return The SoapObject returned by the Stored Proc call
* @throws Exception
*/
private static SoapObject callProcServiceForObject(String serviceMethod, String storedProc, String params) throws Exception {
String NAMESPACE = "http://" + GlobalVars.serviceIP + "/";
String METHOD_NAME = getMethodName(serviceMethod);
String SOAP_ACTION = NAMESPACE + METHOD_NAME;
String URL = "http://" + GlobalVars.serviceIP + "/ATService.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
if (GlobalVars.encryptedService) {
request.addProperty("ePassword", CryptUtil.encryptString(GlobalVars.deviceSerialNumber));
request.addProperty("eData", CryptUtil.encryptString(GlobalVars.serverDB));
request.addProperty("eSP_Name", CryptUtil.encryptString(storedProc));
request.addProperty("eParam", CryptUtil.encryptString(params));
} else {
request.addProperty("sPassword", GlobalVars.deviceSerialNumber);
request.addProperty("sData", GlobalVars.serverDB);
request.addProperty("sSP_Name", storedProc);
request.addProperty("sParam", params);
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// Enable the below property if consuming .Net service
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeout);
//count up the network traffic
numberOfBytesTransmitted = numberOfBytesTransmitted + StringToBytes(request.toString());
SoapObject returnable = null;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
returnable = (SoapObject)envelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Msg:" + e.getMessage() + "; SP:" + storedProc + "; Params: " + params + "; Method:" + METHOD_NAME);
}
numberOfBytesTransmitted = numberOfBytesTransmitted + StringToBytes(returnable.toString());
return returnable;
}
任何人都跳出来了?
答案 0 :(得分:0)
显然,我没有在我的.Net服务上设置网络配置文件,它与Android Studio完全无关。