0

I have a web service in .net and I call it from android in localhost. It is to show a string in emulator display but it's not working. It shows access denied in the emulator.

SoapTestActivity.java

package com.sample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;



public class SoapTestActivity extends Activity {
    TextView result;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        result = (TextView)findViewById(R.id.result);

        final String NAMESPACE = "http://sample.com/";
        final String METHOD_NAME = "SayHello";    
        final String SOAP_ACTION = "http://sample.com/SayHello";
        final String URL = "http://192.168.1.108/WebService1/Service1.asmx";

        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);            
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            String resultValue = response.toString();

            result.setText(resultValue);           
        }
        catch (Exception e) {
            result.setText(e.getMessage());
        }
    }
}

manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sample.SoapTestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

the url shown i the firefox browser is

http://localhost:5460/Service1.asmx
sadab
  • 59
  • 2
  • 7

1 Answers1

0

please change url 192.168.1.108 to 10.0.2.2:80

After changing this, u will get data on your Emulator

please refer http://developer.android.com/tools/devices/emulator.html#networkaddresses for more reference.

Karan Maru
  • 991
  • 6
  • 17