Android网络服务问题

时间:2011-04-29 13:00:03

标签: android web-services ksoap2

package com.demowold;

import android.app.Activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE; 

public class DemoWold extends Activity {

private EditText etUserName;
private TextView lblResult;
/** Called when the activity is first created. */

private static final String NAMESPACE = "http://tempuri.org";
private static final String METHOD_NAME = "Hello";
private static final String SOAP_ACTION = "Hello";
private static final String URL = "http://ip/foldername/UserAuthenticationService.svc?wsdl";


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


    lblResult = (TextView) findViewById(R.id.lblmsg);
    etUserName = (EditText)findViewById(R.id.etUserName); 

       call();

}

public void call()
{
        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.debug =true;
        try
        {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            lblResult.setText(envelope.getResponse().toString());
        }
        catch(org.xmlpull.v1.XmlPullParserException ex2)
        {      
            lblResult.setText(androidHttpTransport.requestDump.toString());         
            System.out.println(androidHttpTransport.requestDump.toString());

        }     

            } catch (Exception e) {

        lblResult.setText(e.toString());
    }
}
}

我收到错误:

org.xmlpull.v1.XmlPullParserException: unexpected type 
    (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@44c25e10)  

请帮帮我。代码中有什么问题

2 个答案:

答案 0 :(得分:0)

我认为您的网址:http://ip/foldername/UserAuthenticationService.svc?wsdl可能是问题所在。尝试http://ip/foldername/UserAuthenticationService.svc(假设ip和foldername将被真实的替换!)

如果它不起作用,您可以在请求后发布androidHttpTransport.responseDump中的内容吗?

答案 1 :(得分:0)

METHOD_NAME和SOAP_ACTION不应该相同。 SOAP_ACTION应该是命名空间和方法名称的串联。在你的情况下,它将是“http://tempuri.org/Hello”。此外,这很重要,在NAMESPACE结束时加上斜线。不幸的是,这是ksoap2初学者的常见问题。

但是,您收到的错误似乎与他们无关。

在检查responseDump时,您在哪里放置了断点?