Android : calling asmx webservice with ksoap2 failed

on Friday, August 29, 2014


i'm struggling to connect my android app with asmx web service using ksoap..


i'm getting http request failed status 400.


my web service is a simple helloworld:



namespace dbservice
{
/// <summary>
/// Summary description for dbservice
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class dbservice : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}


my mainAcitivity:



public class MainActivity extends ActionBarActivity {

Button save;
EditText empname;
TextView view;
EditText mail;

private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:18442/dbservice.asmx";
private static final String OPERATION_NAME ="HelloWorld";
private static final String SOAP_ACTION ="http://tempuri.org/HelloWorld";
String message;
String TAG = "SOAP";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {

}

save = (Button) findViewById(R.id.searchbutton);
empname = (EditText) findViewById(R.id.empname);
view = (TextView) findViewById(R.id.textView1);
mail = (EditText) findViewById(R.id.mail);

save.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
myasynck task = new myasynck();
task.execute();
}
});
}

private final SoapSerializationEnvelope connectSoap(SoapObject request) {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

return envelope;
}

public void getData()
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);

SoapSerializationEnvelope envelope = connectSoap(request);

HttpTransportSE transport = new HttpTransportSE(SOAP_ADDRESS);
try
{
transport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
message = result.toString();

}catch(Exception ex)
{
Log.e("error", ex.getMessage());
}
}
public class myasynck extends AsyncTask<String, Void, Void>
{

@Override
protected Void doInBackground(String... params) {

Log.i(TAG,"backgound");
getData();
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
mail.setText(message);
}

@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
}
}


LogCat:



08-29 05:14:10.476: E/error(3253): HTTP request failed, HTTP status: 400


i have internet permission, i'm using android 4.2


hope somebody here will help..


0 comments:

Post a Comment