Android的accesing SOAP服务 [英] Android accesing soap service
问题描述
我用下面的code访问webserivce
I am using the following code to access the webserivce
public SoapObject getWeather() throws Exception
{
SoapObject request = new SoapObject("http://www.freewebservicesx.com", "GetCurrentGoldPrice");
//request.addProperty("PlaceName", city);
request.addProperty("Username","myusername");
request.addProperty("Password","pass");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
// It seems that it is a .NET Web service because it doesn't work without next line
envelope.dotNet = true;
HttpTransportSE transport = new HttpTransportSE("http://www.freewebservicesx.com/GetGoldPrice.asmx");
transport.call("http://freewebservicesx.com/GetCurrentGoldPrice", envelope);
return (SoapObject) envelope.getResponse();
}
public List<CharSequence> getWeatherForecast()
{
SoapObject obj = null;
try {
obj = getWeather();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
//error is being thrown here
Log.e("error",e.getMessage());
}
SoapObject details = (SoapObject) obj.getProperty("GetCurrentGoldPriceResult");
List<CharSequence> list = new ArrayList<CharSequence>(details.getPropertyCount());
for (int i = 0; i < details.getPropertyCount(); i++) {
Object property = details.getProperty(i);
if (property instanceof SoapObject) {
SoapObject weather = (SoapObject) property;
String day = weather.getProperty("string").toString();
String min = weather.getProperty("string").toString();
//String max = weather.getProperty("MaxTemperatureF").toString();
Log.v("ts is whait ai am ",day);
list.add(day + " :: " + min);
}
}
return list;
}
http://www.freewebservicesx.com/GetGoldPrice.asmx?op=GetCurrentGoldPrice 包含了服务的细节。我得到一个失败的粘结剂交易eror。
http://www.freewebservicesx.com/GetGoldPrice.asmx?op=GetCurrentGoldPrice contains the details of the service. I get a failed binder transaction eror.
11月4日至七日:10:01.405:W / System.err的(651)的SOAPFault - 故障code:香皂:服务器'faultstring:System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.ArgumentNullException:值不能为空
04-07 11:10:01.405: W/System.err(651): SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null.
推荐答案
请更改行:
envelope.dotNet = "true";
到
envelope.dotNet = "false";
由于真总是发送一个空值的web服务器,所以设置一个虚假的。
because "true" is always send a null value to webserver,so set a false..
和其他东西...在你的code
and other thing.. in your code
request.addProperty("Username","myusername");
request.addProperty("Password","pass");
在客户端和服务器端的web服务必须是相同的检查您的参数名称(用户名,密码),这意味着它是区分大小写的。
Check your parameter name (Username,Password) on both client and server side webservice that must be same, it means it's case sensitive.
我希望code你的帮助。
I hope code help you.
这篇关于Android的accesing SOAP服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!