XML を表す次の文字列があります。
String soapCall="<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Body xmlns:m="http://www.example.org/stock"> <m:addDownloadParams> <m:idApp>";
soapCall+=idApp;
soapCall+="<m:versionApp>";
soapCall+=versonApp;
soapCall+="</m:versionApp> <m:os>Android</m:os> </m:addDownloadParams> </soap:Body> </soap:Envelope>";
そして、私はこの石鹸のウェブサービスを持っています:
http://stats.mywebsite.com/ws/adddownload
今、その文字列を Android の SOAP Web サービスに渡す必要がありますが、方法がわかりません。httpcliente を使用する必要があることはわかっています。
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
しかし、その文字列でsoapwebserviceを呼び出す方法がわかりません。
誰でもコード例を持っていますか? 私はグーグルでそれを見つけることができません。ライブラリを使いたくない、自分でやる必要がある
ありがとう
編集:これは現在のコードですが、機能していません.エラー500内部サーバーエラーが発生します:
public static byte[] addDownloadIntoServer(){
byte[] result = null;
String SERVER_URL="http://stats.mywebsite.com/ws/server.php";
String SOAP_ACTION="addDownload";
String body="<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://stats.mobincube.com/\"><SOAP-ENV:Body><ns1:addDownloadParams>";
body+="<idApp>" +SectionManager.instance.app_id+"</idApp>";
body+="<versionApp>"+SectionManager.instance.app_version+"</versionApp>";
body+="<source>android</source> <os>Android</os> </ns1:addDownloadParams></SOAP-ENV:Body></SOAP-ENV:Envelope>";
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 15000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 35000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
/*
* httpclient.getCredentialsProvider().setCredentials( new
* AuthScope("os.icloud.com", 80, null, "Digest"), new
* UsernamePasswordCredentials(username, password));
*/
HttpPost httppost = new HttpPost(SERVER_URL );
httppost.setHeader("soapaction", SOAP_ACTION);
httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
System.out.println("executing request" + httppost.getRequestLine());
//now create a soap request message as follows:
final StringBuffer soap = new StringBuffer();
soap.append("\n");
soap.append("");
// this is a sample data..you have create your own required data BEGIN
soap.append(" \n");
soap.append(" \n");
soap.append("" + body);
soap.append(" \n");
soap.append(" \n");
/* soap.append(body); */
// END of MEssage Body
soap.append("");
Log.i("SOAP Request", ""+soap.toString());
// END of full SOAP request message
try {
HttpEntity entity = new StringEntity(soap.toString(),HTTP.UTF_8);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);// calling server
HttpEntity r_entity = response.getEntity(); //get response
Log.i("Reponse Header", "Begin..."); // response headers
Log.i("Reponse Header", "StatusLine:"+response.getStatusLine());
Header[] headers = response.getAllHeaders();
for(Header h:headers)
Log.i("Reponse Header",h.getName() + ": " + h.getValue());
Log.i("Reponse Header", "END...");
if (r_entity != null) {
result = new byte[(int) r_entity.getContentLength()];
if (r_entity.isStreaming()) {
DataInputStream is = new DataInputStream(
r_entity.getContent());
is.readFully(result);
}
}
}catch (Exception E) {
Log.i("Exception While Connecting", ""+E.getMessage());
E.printStackTrace();
}
httpclient.getConnectionManager().shutdown(); //shut down the connection
return result;
}