开发者

Call webservice from Android using KSoap simply returning "error" string

开发者 https://www.devze.com 2022-12-28 11:25 出处:网络
I\'m trying to use ksoap to call a simple webservice.I followed this video to try to get started.When I call \"getResponse()\" on the envelope I just get the string \"Error\".There\'s no exceptions th

I'm trying to use ksoap to call a simple webservice. I followed this video to try to get started. When I call "getResponse()" on the envelope I just get the string "Error". There's no exceptions thrown or any other detail. I've successfully connected to a simple webservice I just setup on my local machine. Could this potentially be related to being behind a proxy server here at work? My code is below:

String SOAP_ACTION="http://tempuri.org/CelsiusToFahrenheit";
String METHOD_NAME = "CelsiusToFahrenheit";
String NAMESPACE = "http://tempuri.org";
String URL = "http://w3schools.com/webservices/tempconvert.asmx";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("Celsius");
pi.setValue("32");
request.addProperty(pi);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

HttpTransportSE aht = new HttpTransportSE(URL);

try
{
    aht.call(SOAP_ACTION, envelope);
    SoapPrimitive results = (SoapPrimitive)envelope.开发者_JAVA百科getResponse();
}
catch (Exception e)
{
    e.printStackTrace();
}


Turns out I was missing a '/' after the namespace. Took me way too long to figure that out.


You should write namespace like this.

String NAMESPACE = "http://tempuri.org"/;
0

精彩评论

暂无评论...
验证码 换一张
取 消