请任何人设置此代码,我已经尝试了几种不同的代码来解析soap-envelop如何处理这种类型的响应
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
答案 0 :(得分: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 Fault Object的”detail“节点” 尝试使用.getproperties()
进行手动解析并了解更多信息 http://docs.oracle.com/cd/E19159-01/819-3669/bnbin/index.html