Android 网络服务问题

发布于 2024-11-03 18:38:18 字数 2151 浏览 2 评论 0原文

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)  

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

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

i am getting error :

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

please help me . what is the wrong in code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筑梦 2024-11-10 18:38:18

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

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

I think your URL: http://ip/foldername/UserAuthenticationService.svc?wsdl might be the problem. Try http://ip/foldername/UserAuthenticationService.svc (supposing ip and foldername will be replaced by the real ones!)

If it doesn't work, could you post what's in androidHttpTransport.responseDump after the request?

最笨的告白 2024-11-10 18:38:18

METHOD_NAME 和 SOAP_ACTION 不应相同。 SOAP_ACTION 应该是命名空间和方法名称的串联。在您的情况下,它将是“http://tempuri.org/Hello”。另外,这一点很重要,请在 NAMESPACE 末尾添加斜杠。不幸的是,这是 ksoap2 初学者的常见问题。

不过,您收到的错误似乎与他们无关。

当你检查responseDump时你把断点放在哪里了?

The METHOD_NAME and SOAP_ACTION should not be the same. SOAP_ACTION is supposed to be a concatenation of the namespace and method name. In your case it would be "http://tempuri.org/Hello". Also, and this is important, put a slash at the end of NAMESPACE. This is a common problem for ksoap2 beginners, unfortunately.

The error you received doesn't really seem related to them, though.

Where did you put the breakpoint when you inspected responseDump?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文