Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is main class:

Java
package com.mimaratha.webservices;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;



public class MainActivity extends AppCompatActivity{

    public static String rslt="";    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b1=(Button)findViewById(R.id.button);
        final  AlertDialog ad=new AlertDialog.Builder(this).create();

        b1.setOnClickListener(new OnClickListener() {

            @Override public void onClick(View arg0) {
                // TODO Auto-generated method stub

                try
                {
                    EditText ed1=(EditText)findViewById(R.id.editText1);
                    EditText ed2=(EditText)findViewById(R.id.editText2);
                    int a=Integer.parseInt(ed1.getText().toString());
                    int b=Integer.parseInt(ed2.getText().toString());
                    rslt="START";
                    Caller c=new Caller(); c.a=a;
                    c.b=b;
                    c.ad=ad;
                    c.join(); c.start();
                    while(rslt=="START") {
                        try {
                            Thread.sleep(10);
                        }catch(Exception ex) {
                        }
                    }
                    ad.setTitle("RESULT OF ADD of "+a+" and "+b);
                    ad.setMessage(rslt);
                }catch(Exception ex) {
                    ad.setTitle("Error!"); ad.setMessage(ex.toString());
                }
                ad.show();
            } });
    }


child classes:
C#
package com.mimaratha.webservices;

public class Caller  extends Thread
{
    public CallSoap cs;
    public int a,b;

    public void run(){
        try{
            cs=new CallSoap();
            String resp=cs.Call(a, b);
            MainActivity.rslt=resp;
        }catch(Exception ex)
        {MainActivity.rslt=ex.toString();}
    }


C#
package com.mimaratha.webservices;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class CallSoap
{
    public final String SOAP_ACTION = "http://tempuri.org/Add";

    public  final String OPERATION_NAME = "Add";

    public  final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

    public  final String SOAP_ADDRESS = "http://grasshoppernetwork.com/NewFile.asmx";
    public CallSoap()
    {
    }
    public String Call(int a,int b)
    {
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
        PropertyInfo pi=new PropertyInfo();
        pi.setName("a");
        pi.setValue(a);
        pi.setType(Integer.class);
        request.addProperty(pi);
        pi=new PropertyInfo();
        pi.setName("b");
        pi.setValue(b);
        pi.setType(Integer.class);
        request.addProperty(pi);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        Object response=null;
        try
        {
            httpTransport.call(SOAP_ACTION, envelope);
            response = envelope.getResponse();
        }
        catch (Exception exception)
        {
            response=exception.toString();
        }
        return response.toString();
    }
}


What I have tried:

i called web service in android but its getting error
Posted
Updated 10-Mar-16 2:17am
Comments
Richard MacCutchan 10-Mar-16 7:39am    
Where is the variable ad defined? It would probably be easier to spot errors like this if you used meaningful names for variables.

1 solution

In the snippet
C#
Caller c=new Caller(); c.a=a;
                    c.b=b;
                    c.ad=ad;
You are attempting to assign the AlertDialog ad to the property ad of the object c but class Caller does not have a property called that, nor does the base class Thread
 
Share this answer
 

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