1

I am developing an app for testing asp.net webservice in android.for that a simple webservice for adding two numbers is used.where the numbers are passed as parameters.the result is get in an dialogue.the webserver works in local. when the application runs following result get as an exception.i provided the internet permission in manifest.

java.net.UnknownHostException(Unable to resolve host “http://url.com/”: No address associated with hostname)

my code given below

Main Activity

    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.button1);
        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(); 
        } });
    }
}

Caller.java

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();
        }
    }
}

CallSoap.java

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 = "url";
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+OPERATION_NAME, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}

please help me.thanks in advance.

1
  • I know this question was already answered, but turning my Wi-Fi on fixed this Exception for me. I tried posting it as an answer, but my opinion that it qualifies as such has been overruled. Commented Sep 5, 2014 at 17:54

1 Answer 1

1

I think you are testing it in an Emulator. Since the service is in a real server, I prefer using a real device. Also, using emulator is OK. But some emulator shows weird behavior with real web services. Try using a different emulator, preferably a newly created one.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks nizam..its work for me..may i know the reson?
Appam thinna pore.. :P Since it is "Emulator", bugs may occur, either internally or by your previously installed apps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.