我有一个用asp.net编写的have服务。我想从安卓应用程序使用SOAP(ksoap2)访问webservice。
这是我的soap片段,
//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();线路..。
我想我得不到webservice的响应。我怎么才能修复它?
Webservice返回xml.InnerText。它是字符串类型。
请回答我。
发布于 2014-12-14 00:11:38
虽然我不是.NET开发人员,但我在使用Java之前见过类似的错误代码,它总是归结为调用web service返回的XML无效。
在我的例子中,我尝试捕获原始XML响应,然后尝试使用XML解析库解析它。
https://stackoverflow.com/questions/27460513
复制相似问题