4

thanks for your attention.

I have a problem on using ksoap2 to call a webservice via android.

I have some function to call a webservice.

public String CallWebServiceFunction()
{
        String WSDL_TARGET_NAMESPACE = "http://MyWeb.com/";
        String SOAP_ADDRESS = "http://MyWeb.com/pvws.asmx";
        String SOAP_ACTION = "http://MyWeb.com/SoapAction";
        String OPERATION_NAME = "SoapAction";

        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

        PropertyInfo prop1 = new PropertyInfo();
        prop1.setName("prop1");
        prop1.setValue("1");

        request.addProperty(prop1);

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

}

When I use emulator (or real device), which using API 16 or above (Android 4.x) - everything is OK, function gets correct response from webservice. But when I use emulator (or real device) with API 7 (Android 2.x) - then I get an exception

"java.net.UnknownHostException: Host is unresolved: MyWeb.com:80"

I use the same code in both cases, trying one after another - and I get different results

Did anybody has any ideas?

UPD1: Permission section from my manifest is

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

UPD2: Hypothesis. Initially I created my app for targetSdkVersion=16. Therefore I use multi-threaded code, when I call webservice via Internet. Maybe, when it works with API7, source code shouldn't be multi-threaded?

UPD3: Hypothesis was wrong. Calling webservice from main thread causes the same exception.

But I noticed, that when I run my project on another computer - it works correctly. Despite I use the same code.

user2775914
  • 193
  • 1
  • 9

3 Answers3

1
UnknownHostException:host is unresolved

Make sure you have added permission in your AndroidManifest.xml like this

<uses-permission android:name="android.permission.INTERNET" />

and also Make sure its added inside <manifest> tag not inside any other tags like <application> etc

PS.

Also Make sure for following permissions

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />    
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
  • I added my permission section above. And I have to stress - when I use API16-emulator - everything is all right. Therefore, everything is OK both with internet connection and with "MyWeb.com" – user2775914 Sep 13 '13 at 10:55
  • Thank you. I hadn't "READ_PHONE_STATE" permission. But adding of this permission didn't help unfortunately. – user2775914 Sep 13 '13 at 11:22
0

I think for Android 2.x absent android.permission.READ_PHONE_STATE.

Try it,

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
0

Please check your data connection or wifi is ON

then go to manifest and check for internet

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
CrazyMind
  • 1,006
  • 1
  • 20
  • 22