こんにちは、アプリケーションで SOAP サービスを使用しています。SOAP サービスは、mozilla firefox REST クライアントおよび SOA クライアントで動作します。
リクエスト本文:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/IService/GetData</a:Action>
</s:Header>
<s:Body>
<GetData xmlns="http://tempuri.org/"><value>Hello</value></GetData>
</s:Body>
</s:Envelope>
コード:
private final String raw1 = "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">" +
"<s:Header>" +
"<a:Action s:mustUnderstand=\"1\">http://tempuri.org/IService/GetData</a:Action>" +
"</s:Header>" +
"<s:Body>" +
"<GetData xmlns=\"http://tempuri.org/\">" +
"<value>Hello</value>" +
"</GetData>" +
"</s:Body>" +
"</s:Envelope>";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URL);
post.setHeader("Content-type", "application/soap+xml");
post.setHeader("charset", "utf-8");
try {
post.setEntity(new StringEntity(raw1, "UTF8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
HttpResponse response = client.execute(post);
Log.d("test", ""+response.getStatusLine());
InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String str, res = "";
while((str = br.readLine()) != null) {
res += str;
}
br.close();
is.close();
Log.d("test", ""+res);
} catch(Exception e) {
e.printStackTrace();
}
この生のリクエスト本文を使用して手動で http 投稿を作成すると、Android アプリケーションでサービスをヒットできましたが、 ksoap2 を使用すると
private String NAME_SPACE = "http://tempuri.org";
private String METHOD_NAME = "GetData";
private final String URL = "http://example.amazonaws.com/PresenceServices/Service.svc";
private final String SOAP_ACTION = "http://tempuri.org/IService/GetData";
SoapObject request = new SoapObject(NAME_SPACE, METHOD_NAME);
request.addProperty("value", "hello");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Log.e("Object response", response.toString());
return response;
} catch (Exception e) {
e.printStackTrace();
}
IOExceptionをスローします Http Request Failed Http status 500
ksoap2でこれを達成するのを手伝ってください。