org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@4052b038)
这是我的代码:
package asdd.sd;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
public class AsdasdActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String nameSpace = "http://findmydroid.com/";
String methodName = "GetData";
String soapAction = "http://findmydroid.com/GetData";
String url = "http://10.0.2.2/FindMyDroid/Service1.svc";
SoapObject soapObject = new SoapObject(nameSpace, methodName);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transport = new HttpTransportSE(url);
PropertyInfo pi = new PropertyInfo();
pi.setName("value");
pi.setValue(55);
soapObject.addProperty(pi);
try
{
transport.call(soapAction, envelope);
String dump = transport.requestDump;
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
boolean result = Boolean.parseBoolean(response.toString());
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
这是我的网络服务的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace FindMyDroid.WCF
{
[ServiceContract(Namespace = "http://findmydroid.com/")]
public interface IService1
{
[OperationContract]
string GetData(int value);
// TODO: Add your service operations here
}
}
Here is the Service1 Class
namespace FindMyDroid.WCF
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
我想做的只是测试服务,所以我知道我可以用Java连接到它,如果有人可以帮我解决这个错误。我从这里(Stackoverflow)和其他网站尝试了很多不同的例子。我试过在Visual Studio的ASP主机和IIS中托管服务。我尝试用我的外部IP地址调用它,但没有结果。
答案 0 :(得分:0)
根据我的经验,XMLParser正在尝试解析它收到的响应;虽然在这种情况下,它接收的响应可能是HTML格式。
XMLParser实际上指定它不识别类型:
position:END_DOCUMENT null@1:0
在我的情况下,响应通常是错误500或错误404 HTML文档。一旦我确定了错误响应的内容,我就可以将调用定向到正确的URL并收到正确的响应。