开发者

problem getting the .NET web service response?

I'm new to this android apps, so i developed a sample .net web service app and putted this service in another machine IIS server and calling from there to my system. But i didn't getting response everything looks fine, so 'm placing my code on skydrive so please download my code "Android app and .net service.rar" from below link and check it and tell me what's wrong in that from 2 days i'm struggling with that :(

This is my code...

.net web service code:

[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService]

public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string MobileApp(string type) 
    {
        return "Type is"+type;
    }

}

Service call code in eclipse:

public void ServiceCall()
    {
        try{
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
        request.addProperty("type",view1.getText().toString());

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

        //@SuppressWarnings("deprecation")
        //ndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug=true;

        androidHttpTransport.call(SOAP_ACTIO开发者_运维问答N, envelope);

        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
        TextView txtView=(TextView)findViewById(R.id.txtSer);
                txtView.setText(result.toString());

        }       
        catch (final IOException e)

        {
            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (final XmlPullParserException e)

        {

            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (final Exception e)

        {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }


    }

Lines added in manifest:

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

@nag


Should be these but i don't know how is your webservice please give more if these do not work.

request.addProperty("type",view1.getText().toString() );


If you have your web service running on one pc and (I assume) your android app running on another pc on the emulator - I'm not sure how the emulator networks to another local pc - this might be part of your problem. Try running your web service on the same pc as the emulator as localhost but use port 10.0.2.2 to connect to it from your application code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜