Hey everyone i am trying to access a simple web service that add two digits , now i know many have asked this question but i have seriously tried nearly every solution i've seen , most of them were correct the namespace , soap address etc , but i mine is absolutely correct . I m going crazy because i've been at this for the last 8 hours and no success -_- . So plzz help anyone. First of all i am try this for the first time so i really don't have a lot of knowledge about soap , the code u see , i picked most of it . But i also understand most of it.
package com.example.usingaddservice;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.R.integer;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity
{
private static final String SOAP_ACTION = "http://tempuri.org/add";
private static final String OPERATION_NAME = "add";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:42875/Service.asmx";
EditText e1,e2;
Button button;
TextView ans;
int a,b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.editText1);
e2 = (EditText) findViewById(R.id.editText2);
ans = (TextView) findViewById(R.id.ans);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
a = Integer.parseInt(e1.getText().toString());
b = Integer.parseInt(e2.getText().toString());
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("a");
propertyInfo.setValue(a);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
propertyInfo=new PropertyInfo();
propertyInfo.setName("b");
propertyInfo.setValue(b);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
ans.setText(response.toString());
} catch (Exception e) {
Log.d("Errror is", e.getClass()+" "+e.getMessage());
}
}
});
}
}
and my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.usingaddservice.MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:ems="10" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="158dp"
android:text="Button" />
<TextView
android:id="@+id/ans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="73dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
LOGCAT gave this exception in try catch
Errror is : class org.xmlpull.v1.XmlPullParserException expected: START_TAG {http://www.w3.org/2003/05/soap-envelope}Envelope (position:START_TAG <HTML>@2:7 in java.io.InputStreamReader@40551fd8)
My service is working fine , so plzzz if someone can help me i'll really appreciate it :)