如何从Android上调用IIS服务器上托管的.svc Web服务?

时间:2013-08-31 15:20:58

标签: android web-services ksoap2 svc

我正在使用.svc webservices并解析我正在使用Ksoap2方法,现在,当我调用该服务时,它会给我以下错误:

这是我的代码: -

private final String NAMESPACE = "http://tempuri.org/";
    private final String URL = "http://myserver/Manager/api/public/Login.svc";
    private final String SOAP_ACTION = "http://tempuri.org/Public/Login/ChangePassword";
    private final String METHOD_NAME = "ChangePassword";

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

        ok = (Button)findViewById(R.id.btnok);

        ok.setOnClickListener(new OnClickListener() 
        {

            public void onClick(View v) 
            {
                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                    request.addProperty("oldPassword","123");
                    request.addProperty("newPassword","123456789");

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

                    try 
                    {
                        androidHttpTransport.call(SOAP_ACTION, envelope);
                        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
                        SoapObject obj1 = (SoapObject)envelope.bodyIn;
                        Log.v("myApp", "SoapObject Result: "+obj1.toString());
                        Log.v("myApp", "SoapPremitive Response : "+response.toString());

                       request = null;

                    } 
                    catch (Exception e) 
                    {
                        e.printStackTrace();
                        Log.d("Exception Generated", ""+e.getMessage());
                    }
            }
        });

    }

它给我以下错误:

08-31 20:46:09.350: W/System.err(8907): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@40535160) 
08-31 20:46:09.360: W/System.err(8907):  at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
08-31 20:46:09.360: W/System.err(8907):  at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:1413)
08-31 20:46:09.360: W/System.err(8907):  at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
08-31 20:46:09.360: W/System.err(8907):  at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
08-31 20:46:09.360: W/System.err(8907):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:214)
08-31 20:46:09.360: W/System.err(8907):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
08-31 20:46:09.360: W/System.err(8907):  at com.example.soapdemo.MainActivity.FetchData(MainActivity.java:83)
08-31 20:46:09.360: W/System.err(8907):  at com.example.soapdemo.MainActivity$AsynCall.doInBackground(MainActivity.java:42)
08-31 20:46:09.360: W/System.err(8907):  at com.example.soapdemo.MainActivity$AsynCall.doInBackground(MainActivity.java:1)
08-31 20:46:09.360: W/System.err(8907):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-31 20:46:09.360: W/System.err(8907):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-31 20:46:09.369: W/System.err(8907):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-31 20:46:09.369: W/System.err(8907):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-31 20:46:09.369: W/System.err(8907):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-31 20:46:09.369: W/System.err(8907):  at java.lang.Thread.run(Thread.java:1019)

0 个答案:

没有答案