I would like to connect to my WCF WebService on Android project. I follow tutorial
http://javatutorialspoint.blogspot.com/2012/02/android-web-service-access-using-ksoap2.html
but I got 415 error. Maybe there is other simply way to connect? Or I should fix something?
04-16 10:57:10.675: E/WS(4858): java.io.IOException: HTTP request failed, HTTP status: 415
it's url of my web service (it's local) 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();
}
}
I check my connection to WebService with chrome://soaclient/content/webservices.xul and everything looks fine. I've got Operation: GetAddonsTypes and Status: 200 OK.
I'm a Chinese developer,so my English is poor. I had the same problem,solved it by changing SoapEnvelope.VER12 to SoapEnvelope.VER10. Problem is solved,but I do not knew why. My wsdl file is xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" so the version should be 12,not 10.
我有同样的问题,通过在WCF服务的端点配置上将WsHttpBinding更改为basicHttpBinding来解决
this may helps you make Request
Like
private static final String URL =
"http://give Here Server Ipaddress/AndroidWSTest/services/PrintMsg?wsl";
means give current update ipaddress
also make sure your passing
(NAMESPACE, METHOD_NAME)
is correct and match with webServie
Method name
and Namespace
also check Intenet Conncetion
and webservice
working fine Server
side or Not
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.