最終的に私の最大の問題は、私がHttpPostに渡していたURLとSAPのksoap2がまったく役に立たなかったことです。
private void testCallingService() {
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("ip here", port here),
new UsernamePasswordCredentials(username, password));
try {
String buffer = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='namespace'><soapenv:Header/><soapenv:Body><urn:methodname><USERNAME>test</USERNAME></urn:methodname></soapenv:Body></soapenv:Envelope>";
HttpPost httppost = new HttpPost(url);
StringEntity se = new StringEntity(buffer, HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setHeader("Content-Type",
"application/soap+xml;charset=UTF-8");
httppost.setEntity(se);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("ip", port),
new UsernamePasswordCredentials(username, password));
httpclient.setCredentialsProvider(credsProvider);
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
.execute(httppost);
if (httpResponse.getStatusLine() != null) {
System.out.println("Http status: "
+ httpResponse.getStatusLine());
}
RequestLine requestLine = httppost.getRequestLine();
String response = getResponseBody(httpResponse); // read server response. response.getEntity().getContent();...
System.out.println("response: " + response);
} catch (IOException e) {
// TODO Auto-generated catch block
}
httpclient.getConnectionManager().shutdown();
}
私は自分自身でSOAPエンベロープを構築しましたが、近いうちにこれをやめようとします。 CredentialsProviderのインスタンスを作成し、ユーザー/パスの詳細を設定します。サーバーからのステータスは200で、私は必要な情報を受け取ります。 1つの問題は、応答が明らかに大きすぎることです(そして、ここでは停止しません)ので、私の応答は切り捨てられます。それを今解決するために働く。 私はこれが誰かを助けることを本当に願っています。
アンドロイドと競合している場合を除き、動作するはずです。 – kosa
http://www.wiseandroid.com/post/2010/07/16/Porting-existing-Java-code-to-Android.aspxしかし、それはいくつかのアンドロイドは好きではないと言います。 – sealz
これは私が興味を持っていることですが、パッケージjavax.xmlがアンドロイドのデフォルトパッケージになく、コアライブラリをインポートすることがコンパイルできないため、通常アンドロイドと競合します。私は、Javaプロジェクトのインポートが同じ結果にならないことを期待していました。アンドロイドはこれらのクラスについて不平を言っていました。 – user1140656