0
任何人都可以幫助我用ksoap2解析這個xml嗎?使用ksoap2解析XML
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetTurnoverResponse
xmlns="http://tempuri.org/">
<GetTurnoverResult
xmlns:a="http://schemas.datacontract.org/2004/07/blablabla"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Turnover>
<a:Amount>369.2000000</a:Amount>
<a:CurrencyID i:nil="true"/>
<a:DateAndTime>2010-10-01T10:00:00</a:DateAndTime>
<a:ForeignAmount>461.50</a:ForeignAmount>
<a:ForeignCurrencyID>Euro</a:ForeignCurrencyID>
<a:StoreNumber>101</a:StoreNumber>
</a:Turnover>
</GetTurnoverResult>
</GetTurnoverResponse>
</s:Body>
</s:Envelope>
我不確定實際上我是否收到任何回覆。因此我無法解析它。
請求XML是象下面這樣:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.datacontract.org/2004/07/ProFashionAllServices">
<SOAP-ENV:Body>
<ns1:GetTurnover>
<ns1:sessionID>12674579771167587539</ns1:sessionID>
<ns1:selection>
<ns2:EndDate>2010-10-01</ns2:EndDate>
<ns2:StartDate>2010-10-01</ns2:StartDate>
</ns1:selection>
</ns1:GetTurnover>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的要求是這樣的:
public class LoadData extends AsyncTask<String, String, Void> {
private static final String SOAP_ACTION = "http://tempuri.org/ITurnoverService/GetTurnover";
private static final String METHOD_NAME = "GetTurnover";
private static final String NAMESPACE = "http://tempuri.org/";
private String response;
private boolean network;
private Context mContext;
public LoadData(Context context) {
mContext = context;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Toast toast = Toast.makeText(mContext, response, Toast.LENGTH_LONG);
toast.show();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(String... arg0) {
//String conString = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getString("url", "http://wsa.pfagroup.nl:1662/OOPServices/");
String URL = "http://wsa.pfagroup.nl:1662/OOPServices/" +"TurnoverService.svc";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("sessionID", arg0[0]);
request.addProperty("EndDate", arg0[1]);
request.addProperty("StartDate", arg0[1]);
Log.i("doINaaaaaaaaaaaa", arg0[1]);
Log.i("doINaaaaaaaaaaaa", arg0[0]);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
network = true;
} catch (HttpResponseException e) {
// TODO Auto-generated catch block
Log.e("HTTPAAAAA", e.getMessage());
//e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("IOAAAAA", e.getMessage());
response = "Check Your Network Connection";
network = false;
//e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
Log.e("XMLAAAAA", e.getMessage());
//e.printStackTrace();
} //send request
if(network){
SoapObject result = null;
try {
result = (SoapObject)envelope.getResponse();
//response = result.getProperty("GetTurnoverResult").toString();
Log.i("responseeeeeeeeee",String.valueOf(result.getPropertyCount()));
} catch (SoapFault e) {
// TODO Auto-generated catch block
Log.e("SOAPAAAA", e.getMessage());
//e.printStackTrace();
}
}
return null;
}
}
了在logcat的顯示錯誤消息:
18610-18895/com.******.*** E/SOAPAAAA﹕ De server kan de aanvraag niet verwerken als gevolg van een interne fout. Voor meer informatie over de fout kunt u IncludeExceptionDetailInFaults inschakelen (vanuit ServiceBehaviorAttribute of vanuit het configuratiegedrag <serviceDebug>) voor de server zodat de uitzonderingsgegevens naar de client worden teruggestuurd, of u kunt tracering inschakelen. Raadpleeg hiertoe de documentatie van Microsoft .NET Framework SDK en controleer de traceringslogboeken voor de server.
是我的要求錯誤?請幫助
nope。找不到SoapObject.setNamespace方法。但我想我是連續添加三個屬性。但是這些是嵌套的。 StartDate和EndDate在sessionID屬性中。這是一個問題? – abidsplanet
對不起,這個函數在propertyinfo中。我正在更新我的答案 – Adem
這也不起作用。同樣的錯誤。但我想我是連續添加三個屬性。但是這些是嵌套的。 StartDate和EndDate在sessionID屬性中。這是一個問題? – abidsplanet