Android KSOAP2 web服务错误
Android KSOAP2 web服务错误,android,Android,04-02 09:39:26.044:W/System.err(13741):org.xmlpull.v1.XmlPullParserException:应为:开始标记{http://schemas.xmlsoap.org/soap/envelope/}信封(位置:java.io中的START_标记@2:7)。InputStreamReader@40d38638) 当我试图将我的android应用程序连接到本地主机上运行的web服务时,我遇到了这个错误 这是KSOAP web服务的完整代码。 目
04-02 09:39:26.044:W/System.err(13741):org.xmlpull.v1.XmlPullParserException:应为:开始标记{http://schemas.xmlsoap.org/soap/envelope/}信封(位置:java.io中的START_标记@2:7)。InputStreamReader@40d38638)
当我试图将我的android应用程序连接到本地主机上运行的web服务时,我遇到了这个错误
这是KSOAP web服务的完整代码。
目前,我正在Eclipse中使用模拟器运行本地主机服务器。尝试在另一个线程中使用您的代码,如下所示
package com.example.weblab;
import org.apache.http.protocol.HTTP;
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.util.Log;
public class WebServiceCaller {
private final String NAMESPACE="http://tempuri.org/";
private final String URL="http://10.0.2.2:8080/Service1.asmx?WSDL";
public String authenticateUser(String usern,String passw)
{
String result = "";
final String SOAP_ACTION="http://tempuri.org/AuthenticateUser";
final String METHOD_NAME="GetUserName";
SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo prinfo=new PropertyInfo();
prinfo.setName("name");
prinfo.setValue(usern);
prinfo.setType(String.class);
request.addProperty(prinfo);
SoapSerializationEnvelope envelop=new SoapSerializationEnvelope(SoapEnvelope.VER11);//ver11 version
envelop.dotNet=true;//only for dotnet
envelop.setOutputSoapObject(request);
HttpTransportSE httptransportse=new HttpTransportSE(URL);
try{
httptransportse.call(SOAP_ACTION, envelop);
SoapPrimitive response=(SoapPrimitive)envelop.getResponse();
Log.i("myapp",response.toString());
result = response.toString();
}catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
代码中的命名空间在哪里。代码中缺少URL和命名空间。我已将代码更新为完整代码
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);