質問

Please anyone set this code,I have tried several different code to parse soap-envelop how to handle this type of response

 public class Main Activity extends Activity
    {
        TextView res;
        String str, he, hh;
         SoapSerializationEnvelope envelope;
        private final String URL = "http://10.0.2.2:port/Service1.svc?wsdl";
        private final String NAMESPACE = "http://tempuri.org/";
         private final String SOAP_ACTION = "http://tempuri.org/IService1/GetData";
         private final String METHOD_NAME = "GetData";

        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Log.d("Hello", "Fault_Exception_WebService Project  Called.........");

             myasynctask MAT = new myasynctask();
             MAT.execute();   
        }


        private class myasynctask extends AsyncTask<Void, Integer, String>
        {

            @Override
            protected void onPreExecute()
            {

            }

            @Override
            protected void onPostExecute(String result) 
            {
                TextView tv= (TextView)findViewById(R.id.heloo);
                tv.setText(he);


            }

            @Override
            protected String doInBackground(Void... params)

            {
                try 
                {

                    // Soap Call

                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                    request.addProperty("value", "1");


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


                    ht.call(SOAP_ACTION, envelope);
                    Log.i("res......", fulatcode.toString());

                }
                catch (SoapFault fault)
                {
                    Log.v("TAG", "soapfault = "+fault.toString());



                    String strFault = ((SoapFault) envelope.bodyIn).faultstring;
                    String strfalutcode =((SoapFault)envelope.bodyIn).faultcode;
                    String strfaultactor =((SoapFault)envelope.bodyIn).faultactor;
                    String strmessage = ((SoapFault)envelope.bodyIn).getMessage();

                    String a= String.valueOf(strmessage);
                    Log.v("TAG", "Message:"+a);
                    Log.v("TAG", "Code:"+strfalutcode.toString()+"String:"+strFault.toString());



                    he="Code:"+strfalutcode.toString()+"String:"+strFault.toString() ;
                }

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

                return null;      

            }

        }
    }

Here is my soap response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <s:Fault>
      <faultcode>s:2</faultcode>
      <faultstring xml:lang="en-US">sdajkgfuio</faultstring>
      <detail>
        <custom_fault xmlns="http://schemas.datacontract.org/2004/07/testing_fault" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <error_code1>2</error_code1>
          <error_code2>3</error_code2>
          <error_message1>There is no employee exist with the emp id</error_message1>
          <error_message2>password is empty</error_message2>
        </custom_fault>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

here is my logcat responce:

12-04 11:54:43.839: V/TAG(1154): soapfault = SoapFault - faultcode: 's:2' faultstring: 'sdajkgfuio' faultactor: 'null' detail: org.kxml2.kdom.Node@41024470
12-04 11:54:43.839: V/TAG(1154): Message:sdajkgfuio
12-04 11:54:43.839: V/TAG(1154): Code:s:2String:sdajkgfuio
役に立ちましたか?

解決

Try this SoapObject tabResult = (SoapObject) tabResponse .getProperty(0);

if not worked than try this

for(int i=0;i<elementData.getPropertyCount();i++)
           {
               SoapObject getAllData = (SoapObject) elementData.getProperty(i);
               if (getAllData instanceof SoapObject) {
                   String data= getAllData.getProperty({property_name}).toString();

               }
           }

       }
       else
       {
             Log.i("No Response","error");
             return null;
       }

and Explore this one http://seesharpgears.blogspot.in/2010/10/ksoap-android-web-service-tutorial-with.html

I got the main problem

you are getting the cast errors edit your question to

"How to parse the "detail" node of the Soap Fault Object using the ksoap api" try manual parsing to do the things using the .getproperties()

and see more http://docs.oracle.com/cd/E19159-01/819-3669/bnbin/index.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top