我有一个用 asp.net 编程的网络服务。我想使用 SOAP(ksoap2) 从 Android 应用程序访问 Web 服务。
这是我的 SOAP fragment ,
//Namespace of the Webservice - can be found in WSDL
private static String NAMESPACE = "http://tempuri.org/";
//Webservice URL - WSDL File location
private static String URL = "http://locationbasedapp.net/Service1.asmx";//Make sure you changed IP address
//SOAP Action URI again Namespace + Web method name
private static String SOAP_ACTION = "http://tempuri.org/";
public static String invokeListLocationsWS(String datetext, String webMethName) {
String xmlDataSet = "";
// Create request
SoapObject request = new SoapObject(NAMESPACE, webMethName);
// Property which holds input parameters
PropertyInfo datetextPI = new PropertyInfo();
PropertyInfo passPI = new PropertyInfo();
// Set Username
datetextPI.setName("datetext");
// Set Value
datetextPI.setValue(datetext);
// Set dataType
datetextPI.setType(String.class);
// Add the property to request object
request.addProperty(datetextPI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
// Assign it to boolean variable variable
xmlDataSet =response.toString();
} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
MapActivity.errored = true;
e.printStackTrace();
}
//Return booleam to calling object
return xmlDataSet;
}
当我调试代码时,出现问题标题中提到的错误。错误出现在
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
线..
我想我无法从网络服务获得响应。我该如何修复它?
Web 服务返回 xml.InnerText。它的类型是字符串。
请回答我。
最佳答案
虽然我不是 .NET 开发人员,但在使用 Java
之前我见过类似的错误代码它总是归结为 XML
被调用 web service
返回无效。
就我而言,我 try catch 原始 XML
响应,然后尝试使用 XML
解析它解析库。
关于java - SoapFault - 故障代码 : 'soap:Server' faultstring: 'Server was unable to process request. 未将对象引用设置为对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27460513/