Android 网络服务问题
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的 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. Tryhttp://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?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?