我正在尝试在我的android项目中使用wcf服务但是我收到以下错误
05-24 02:44:35.995:E / TAG(1731):错误:预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}信封(位置:在java.io.InputStreamReader@b41da630中START_TAG @ 2:7)< / p>
final String NAMESPACE = "http://tempuri.org/";
final String METHOD_NAME = "getWeather";
final String SOAP_ACTION = "http://tempuri.org/IService1/getWeather";
final String URL = "http://10.0.2.2:44482/Service1.svc";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("cityName", "Karachi");
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htp = new HttpTransportSE(URL, 15000);
// int jumpTime = 0;
// progress.setProgress(jumpTime);
htp.call(SOAP_ACTION, soapEnvelop);
response = (SoapObject) soapEnvelop.getResponse()
答案 0 :(得分:0)
愿这对你有所帮助。
private String getDataWebService(){
final String NAMESPACE = "http://tempuri.org/";
final String METHOD_NAME = "getWeather";
final String SOAP_ACTION = "http://tempuri.org/IService1/getWeather";
final String URL = "http://10.0.2.2:44482/Service1.svc";
try{
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo info = new PropertyInfo();
info.setName("city");
info.setValue("city_name");
info.setType(String.class);
Request.addProperty(info);
SoapSerializationEnvelope soapEnvelop= new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.call(SOAP_ACTION, soapEnvelop);
Object response = null;
response = soapEnvelop.getResponse()
return response.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
答案 1 :(得分:0)
好的,谢谢你们的贡献,但我已经解决了我的问题。问题是Visual Studio 2013中的IIS Express服务器。我试图从Android访问我的Web服务,但可能没有配置IIS Express或其他东西。无论如何,解决方案是从项目属性更改您的服务器。从IIS Express更改为 ASP.Net应用程序开发服务器。
PS: Visual Studio 2013不再支持Visual Studio应用程序开发服务器。