我使用KSOAP库从webservice.Following读取XML是我的code,我已经使用:
私有静态字符串SOAP_ACTION_Transaction =http://tempuri.org/Trackdata;
私有静态字符串NAMESPACE_Transaction =http://tempuri.org/;
私有静态字符串METHOD_NAME_Transaction =Trackdata;
私有静态字符串URL_Transaction =https://devraj.charge.com/process/getAndroidData.asmx?WSDL;
我使用ASYN任务调用showdetails()方法。
公共无效showdetails()
{
字符串结果=;
SoapObject resultRequestSOAP = NULL;
SoapObject resultRequestSOAPbody = NULL;
SoapObject请求=新SoapObject(NAMESPACE_Transaction,METHOD_NAME_Transaction);
request.addProperty(类型,支付);
request.addProperty(ID,53);
request.addProperty(量,0.02);
request.addProperty(CCExpMonth,11);
request.addProperty(CCExpYear,22);
request.addProperty(源,GG);
request.addProperty(配置文件ID,748);
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(要求);
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL_Transaction);
androidHttpTransport.debug = TRUE;
尝试
{
androidHttpTransport.call(SOAP_ACTION_Transaction,包);
字符串requestDumpString = androidHttpTransport.requestDump;
的System.out.println(requestDump:+ requestDumpString);
resultRequestSOAP =(SoapObject)envelope.getResponse(); //接收的输出
结果= resultRequestSOAP.getProperty(0)的ToString(); //结果字符串
的System.out.println(输出:+结果);
}赶上(例外五){
e.printStackTrace();
}
}
但是我收到以下错误:
的SOAPFault - 故障code:香皂:服务器在faultstring:System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.NullReferenceException:对象不设置到对象的实例。
这条语句: resultRequestSOAP =(SoapObject)envelope.getResponse(); 有谁能告诉我什么可以是错误我已经解析了其他Web服务以及但是这一个我收到此错误的正常工作。 以下是我的XML数据的一部分:
< XML版本=1.0编码=UTF-8&GT?;
< ClsProcessData的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =http://www.w3.org/2001/XMLSchema的xmlns =HTTP:// tempuri.org/">
<配置文件ID> 748< /配置文件ID>
<编号> 53< / MerchantId>
< InvoiceNum> 53-375< / InvoiceNum>
< InvoiceDescription />
<量GT; 0.02 LT; / InvoiceAmount>
< CCName />
< / ClsProcessData>
任何帮助将AP preciated.Will应该心存感激,如果有人能告诉我的错误。
解决方案 SoapObject resultsRequestSOAP =(SoapObject)envelope.bodyIn;
串responseLocal = resultsRequestSOAP.toString();
试试上面,而不是resultRequestSOAP =(SoapObject)envelope.getResponse();
如果(envelope.bodyIn的instanceof的SOAPFault){
字符串str =((的SOAPFault)envelope.bodyIn).faultstring;
Log.i(,STR);
} 其他 {
SoapObject resultsRequestSOAP =(SoapObject)envelope.bodyIn;
Log.d(WS,将String.valueOf(resultsRequestSOAP));
}
另外,如果你的反应是原始的尝试
SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();
I am using Ksoap library to read xml from a webservice.Following is my code that i have used :
private static String SOAP_ACTION_Transaction = "http://tempuri.org/Trackdata";
private static String NAMESPACE_Transaction= "http://tempuri.org/";
private static String METHOD_NAME_Transaction = "Trackdata";
private static String URL_Transaction = "https://devraj.charge.com/process/getAndroidData.asmx?WSDL";
I am calling showdetails() method using asyn task.
public void showdetails()
{
String result = "";
SoapObject resultRequestSOAP = null;
SoapObject resultRequestSOAPbody =null;
SoapObject request = new SoapObject(NAMESPACE_Transaction, METHOD_NAME_Transaction);
request.addProperty("Type","payment");
request.addProperty("Id",53);
request.addProperty("amount","0.02");
request.addProperty("CCExpMonth",11);
request.addProperty("CCExpYear",22);
request.addProperty("Source","gg");
request.addProperty("profileId",748);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_Transaction);
androidHttpTransport.debug = true;
try
{
androidHttpTransport.call(SOAP_ACTION_Transaction, envelope);
String requestDumpString = androidHttpTransport.requestDump;
System.out.println("requestDump : " + requestDumpString);
resultRequestSOAP = (SoapObject) envelope.getResponse(); // Output received
result = resultRequestSOAP.getProperty(0).toString(); // Result string
System.out.println("OUTPUT : " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
However i am getting the following error:
SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
At this statement: resultRequestSOAP = (SoapObject) envelope.getResponse(); Can somebody tell me what can be the error i have parsed other webservices as well that worked fine however for this one i am getting this error. Following is part of my xml data :
<?xml version="1.0" encoding="utf-8"?>
<ClsProcessData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<ProfileId>748</ProfileId>
<Id>53</MerchantId>
<InvoiceNum>53-375</InvoiceNum>
<InvoiceDescription />
<amount>0.02</InvoiceAmount>
<CCName />
</ClsProcessData>
Any help will be appreciated.Will be thankful if some one can tell me the error.
解决方案SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
String responseLocal = resultsRequestSOAP.toString();
Try the above instead of resultRequestSOAP = (SoapObject) envelope.getResponse();
if (envelope.bodyIn instanceof SoapFault) {
String str= ((SoapFault) envelope.bodyIn).faultstring;
Log.i("", str);
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Log.d("WS", String.valueOf(resultsRequestSOAP));
}
Alternatively if your response is primitive try
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();