[英]Connect to WCF WebService on Android / 415 error
我想連接到Android項目上的WCF WebService。 我按照教程
http://javatutorialspoint.blogspot.com/2012/02/android-web-service-access-using-ksoap2.html
但我收到415錯誤。 也許還有其他簡單的連接方式? 還是我應該解決問題?
04-16 10:57:10.675:E / WS(4858):java.io.IOException:HTTP請求失敗,HTTP狀態:415
它是我的網絡服務的網址(本地) http://hq.fs.com.pl:8090/fs/Integrator
package com.example.fs;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
public class AndroidWSClientActivity extends Activity {
//private static final String SOAP_ACTION = "http://ws.android.com/sayHello";
//private static final String METHOD_NAME = "sayHello";
//private static final String NAMESPACE = "http://ws.android.com/";
//private static final String URL = "http://175.157.229.119:8080/AndroidWSTest/services/PrintMsg?wsdl";
// WS
private static final String SOAP_ACTION = "http://tempuri.org/IntegratorMethods/GetAddonsTypes";
private static final String METHOD_NAME = "GetAddonsTypes";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://hq.fs.com:8090/fs/Integrator?wsdl";
TextView textView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wsclient_page);
textView = (TextView) findViewById(R.id.textView2);
Thread networkThread = new Thread() {
@Override
public void run() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
final String str = response.toString();
runOnUiThread (new Runnable(){
public void run() {
textView.setText(str);
}
});
}
catch (Exception e) {
Log.e("WS", e.toString());
}
}
};
networkThread.start();
}
}
我使用chrome://soaclient/content/webservices.xul檢查到WebService的連接,一切看起來都很好。 我已完成操作:GetAddonsTypes,狀態:200 OK。
我是一名中國開發人員,所以我的英語不好。 我有同樣的問題,通過將SoapEnvelope.VER12更改為SoapEnvelope.VER10來解決。 問題解決了,但我不知道為什么。 我的wsdl文件是xmlns:soap12 =“ http://schemas.xmlsoap.org/wsdl/soap12/”,因此版本應為12,而不是10。
我有同樣的問題,通過在WCF服務的端點配置上將WsHttpBinding更改為basicHttpBinding來解決
這或許可以幫助你做出Request
贊
private static final String URL =
"http://give Here Server Ipaddress/AndroidWSTest/services/PrintMsg?wsl";
意味着提供當前的更新ipaddress
並確保您通過
(NAMESPACE, METHOD_NAME)
是正確的,並且與webServie
Method name
和Namespace
匹配,還可以檢查Intenet Conncetion
和webservice
工作正常Server
端或Intenet Conncetion
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.