5
私は単純なシリアライズされたオブジェクトを返す.Net Webserviceを持っています。どのように私のオブジェクトにSoapObjectをキャストまたは逆シリアル化できますか?
私の.Net webserviceからの応答を得るには、次のコードを用意してください。返されたXMLをオブジェクトに逆シリアル化するにはどうすればよいですか?
SoapPrimitiveの代わりにMyObjectを返したいとします。
private static SoapPrimitive callWebServiceMethod(String url,
String namespace, String methodName,
HashMap<String, Object> parameters, String soapAction)
throws Exception {
Log.i("WebService", "URL: " + url);
Log.i("WebService", "MethodName: " + methodName);
URL myurl = new URL(url);
URLConnection connection = myurl.openConnection();
connection.setConnectTimeout(20 * 1000);
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
httpConnection.disconnect();
SoapObject request = new SoapObject(namespace, methodName);
if (parameters != null) {
String[] keys = new String[0];
keys = (String[]) parameters.keySet().toArray(keys);
Object[] vals = (Object[]) parameters.values().toArray();
for (int i = 0; i < parameters.size(); i++) {
request.addProperty(keys[i], vals[i]);
Log.i("WebService", keys[i] + ": " + vals[i]);
}
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
TimeOutInSeconds * 1000);
androidHttpTransport.call(soapAction, envelope);
return (SoapPrimitive) envelope.getResponse();
}
else
{
httpConnection.disconnect();
throw new Exception(
"Http Error code: " + String.valueOf(responseCode));
}
}
プロパティの代わりに応答XMLをデシリアライズする方法はありますか? – breceivemail
SOAP解析の経験はもうありません。:) – MKJParekh