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