Android 使用KSoap库使用.NET web服务时出错
我一直在使用ksoap库来使用.NETWeb服务。 我得到了这种错误 应为:START_TAG{}信封(在java.io中的位置:START_TAG@1:7)。InputStreamReader@40d0c7d8)" 我到处找了,但找不到什么好的帮助 下面是我尝试使用web服务的代码Android 使用KSoap库使用.NET web服务时出错,android,ksoap,Android,Ksoap,我一直在使用ksoap库来使用.NETWeb服务。 我得到了这种错误 应为:START_TAG{}信封(在java.io中的位置:START_TAG@1:7)。InputStreamReader@40d0c7d8)" 我到处找了,但找不到什么好的帮助 下面是我尝试使用web服务的代码 public class WebInvoke { private static final String NAMESPACE = "http://tempuri.org/" ; private s
public class WebInvoke {
private static final String NAMESPACE = "http://tempuri.org/" ;
private static final String METHOD_NAME = "login";
private static final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
private static final String URL = "http://10.0.2.2/Service1.asmx";
private final SoapSerializationEnvelope envelope;
public WebInvoke()
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo quotesProperty = new PropertyInfo();
quotesProperty.setName("UserName");
quotesProperty.setValue("admin");
quotesProperty.setType(String.class);
request.addProperty(quotesProperty);
quotesProperty = new PropertyInfo();
quotesProperty.setName("Password");
quotesProperty.setValue("a");
quotesProperty.setType(String.class);
request.addProperty(quotesProperty);
Log.e("Request Assign", request.toString());
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Log.e("Envelope Assign", envelope.toString());
}
public String Fetch()
{
String result = "";
HttpTransportSE httpRequest = new HttpTransportSE(URL);
try
{
envelope.xsd = SoapSerializationEnvelope.XSD;
envelope.enc = SoapSerializationEnvelope.ENC;
httpRequest.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
Log.e("httpRequest.call", "httpRequest.call");
httpRequest.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
result = response.toString();
}
catch(Exception e)
{
//e.printStackTrace();
Log.e("httpRequest.call Exception", e.getMessage());
}
return result;
}
}
公共类WebInvoke{
私有静态最终字符串命名空间=”http://tempuri.org/" ;
私有静态最终字符串方法\u NAME=“login”;
私有静态最终字符串SOAP\u ACTION=名称空间+方法\u名称;
私有静态最终字符串URL=”http://10.0.2.2/Service1.asmx";
私人最终信封;
公共WebInvoke()
{
SoapObject请求=新的SoapObject(名称空间、方法名称);
PropertyInfo QuoteProperty=新的PropertyInfo();
quoteProperty.setName(“用户名”);
quoteProperty.setValue(“管理”);
quoteProperty.setType(String.class);
request.addProperty(quotesProperty);
QuoteProperty=新属性信息();
quoteProperty.setName(“密码”);
QuoteProperty.setValue(“a”);
quoteProperty.setType(String.class);
request.addProperty(quotesProperty);
Log.e(“请求分配”,Request.toString());
信封=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
Log.e(“信封分配”,信封.toString());
}
公共字符串获取()
{
字符串结果=”;
HttpTransportSE httpRequest=新的HttpTransportSE(URL);
尝试
{
envelope.xsd=SoapSerializationEnvelope.xsd;
envelope.enc=SoapSerializationEnvelope.enc;
httpRequest.setXmlVersionTag(“”);
Log.e(“httpRequest.call”、“httpRequest.call”);
httpRequest.call(SOAP\u操作,信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
结果=response.toString();
}
捕获(例外e)
{
//e、 printStackTrace();
Log.e(“httpRequest.callexception”,e.getMessage());
}
返回结果;
}
}
尝试获得更好的代码。你的代码听起来有点笨拙
预期的开始标记错误
看看这个
希望对你有所帮助。我也遇到了这个错误。最终,通过设置这些值,它得到了修复:
String SOAP_ACTION = "BookTypeService";
String METHOD_NAME = "bookType";
String NAMESPACE = "http://192.168.1.3:8080/MyWebService/services/";
String URL = "http://192.168.1.3:8080/MyWebService/services/BookTypeService";
其中,192.168.1.3是我的本地I/p
<wsdl:service name="BookTypeServiceService">
<wsdl:port name="BookTypeService" binding="impl:BookTypeServiceSoapBinding">
<wsdlsoap:address location="http://localhost:8080/MyWebService/services/BookTypeService"/>
</wsdl:port>
</wsdl:service>