0

次のコードを使用して webservice を呼び出しています。Android で Ksoap を使用するのは初めてです。1 つの webservice を呼び出してデータを解析することができました。別の Web サービスを解析するには、次のエラーが発生します。Soapaction、名前空間を設定したパラメーターはすべて正しく設定されています。Web サービスを呼び出すメソッドを作成しました。

public void showdetails()
    {

        String result = "";
        SoapObject resultRequestSOAP = null;
        SoapObject resultRequestSOAPbody =null;

        SoapObject request = new SoapObject(NAMESPACE_Transaction, METHOD_NAME_Transaction);

        request.addProperty("TransactionType","payment");
        request.addProperty("MerchantId","543");
        request.addProperty("amount","0.02");
        request.addProperty("CCNo","4111111111111111");
        request.addProperty("CCExpMonth","11");
        request.addProperty("CCExpYear","22");
        request.addProperty("Source","aa");
        request.addProperty("profileId","788");
        //request.addProperty("ClientIPAddress","120.138.99.2");
       //request.addProperty("GEOCode","0.000000,0.000000");

            //Some more fields that are not mandatory


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_Transaction);
        androidHttpTransport.debug = true;

        try
        {
            androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding= \"UTF-8\"?>");
            androidHttpTransport.call(SOAP_ACTION_Transaction, envelope);
            String requestDumpString = androidHttpTransport.requestDump;
            System.out.println("requestDump : " + requestDumpString);

            resultRequestSOAP = (SoapObject) envelope.bodyIn;
            //  resultRequestSOAP = (SoapObject) envelope.getResponse(); // Output received
            result = resultRequestSOAP.toString(); // Result string
            System.out.println("OUTPUT : " + result);


            if (envelope.bodyIn instanceof SoapFault) 
            {
                String str= ((SoapFault) envelope.bodyIn).faultstring;
                Log.i("TAG", str);
            } else {
                SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                Log.d("WS", String.valueOf(resultsRequestSOAP));
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

    }

次のステートメントで問題が発生します。

resultRequestSOAP = (SoapObject) envelope.bodyIn;

エラーは次のとおりです。

java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject

誰かがこの問題で私を助けてくれませんか.私はたくさん検索しましたが、解決できませんでした.他のWebサービスを呼び出すと、envelope.bodyIn.

4

1 に答える 1

-1

このように試してくださいので、私はあなたのコードを編集しました

SoapObject request = new SoapObject(NAMESPACE_Transaction,
            METHOD_NAME_Transaction); // set up request
    request.addProperty("TransactionType","payment");
    request.addProperty("MerchantId","543");
    request.addProperty("amount","0.02");
    request.addProperty("CCNo","4111111111111111");
    request.addProperty("CCExpMonth","11");
    request.addProperty("CCExpYear","22");
    request.addProperty("Source","aa");
    request.addProperty("profileId","788");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11); // put all required data into a soap
    // envelope
    // envelope.dotNet = true; This is needed else gives error - 42,
    // parameter is not recognised!!
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request); // prepare request
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(
            URL_Transaction);
    httpTransport.call(SOAP_ACTION_Transaction, envelope);

    SoapObject result = (SoapObject) envelope.getResponse();
      System.out.println(result.toString());
于 2013-03-12T11:16:55.313 に答える