Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 
{
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION = "http://tempuri.org/add";

    private static final String OPERATION_NAME = "add";// your webservice web method name

    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.type = PropertyInfo.INTEGER_CLASS;                    
                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

XML
<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 :)
Posted
Updated 5-Apr-15 5:58am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900