2

请任何人设置此代码,我尝试了几种不同的代码来解析肥皂信封如何处理这种类型的响应

 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;      

            }

        }
    }

这是我的肥皂回应:

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

这是我的 logcat 回复:

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
4

1 回答 1

0

试试这个 SoapObject tabResult = (SoapObject) tabResponse .getProperty(0);

如果不工作,试试这个

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

并探索这个 http://seesharpgears.blogspot.in/2010/10/ksoap-android-web-service-tutorial-with.html

我得到了主要问题

你得到演员错误编辑你的问题

“如何使用 ksoap api 解析 Soap 故障对象的“详细”节点”尝试手动解析以使用 .getproperties()

并查看更多 http://docs.oracle.com/cd/E19159-01/819-3669/bnbin/index.html

于 2013-12-04T07:17:26.770 回答