0

我正在使用 Ksoap 库从 web 服务中读取 xml。以下是我使用过的代码:

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";

我正在使用异步任务调用 showdetails() 方法。

   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();
            }

        }

但是我收到以下错误:

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.

在这个语句中:resultRequestSOAP = (SoapObject) envelope.getResponse(); 有人可以告诉我我已经解析了其他 web 服务的错​​误可能是什么,但是对于这个我得到了这个错误。以下是我的 xml 数据的一部分:

<?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>

任何帮助将不胜感激。如果有人能告诉我错误,将不胜感激。

4

1 回答 1

0
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
String responseLocal = resultsRequestSOAP.toString();

试试上面的而不是 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));
}

或者,如果您的回答是原始的,请尝试

 SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
于 2013-03-11T16:19:33.510 回答