从android调用soap webservice

时间:2013-01-24 08:14:54

标签: android

您好我正在尝试从Android调用Web服务。代码工作正常,没有错误,但我没有输出。我是android的新手。请帮帮我。

整个教程是here ....

有三个按钮 clear button 做得很好,但转换为摄氏转换为fahrenheit 不起作用。 实际上,在try块

中都有声明
SoapObject result = (SoapObject)envelope.bodyIn;

我想在这一行应用程序被卡住了,因为我在每个语句提示之后放置了构建器消息但在此语句之后它没有。 请告诉我是什么问题,我真的很担心..

1 个答案:

答案 0 :(得分:0)

尝试使用此类来调用Web服务:

public class WSRequest {

    public HttpTransportSE androidHttpTransport;
    public SoapSerializationEnvelope envelope; 
    public String methodName;
    public SoapObject request;

    public WSRequest(String methodName)
    {
        this.methodName = methodName;
        this.request = new SoapObject(SRWebServer.NAMESPACE, methodName);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.implicitTypes = true;
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        androidHttpTransport = new HttpTransportSE(SRWebServer.URL);
    }

    public void RegisterMarshal()
    {
        MarshalBase64 marshal = new MarshalBase64();
        marshal.register(envelope);
    }

    public SoapObject Send() throws IOException, XmlPullParserException 
    {
        System.setProperty("http.keepAlive", "false");
        new MarshalDate().register(envelope);
        this.androidHttpTransport.call(SRWebServer.NAMESPACE + this.methodName, envelope);
        return (SoapObject) this.envelope.getResponse();
    }



    public void AddProperties(String name, Object value)
    {
        this.request.addProperty(name, value);

    }
        // 

}

并以这种方式使用:

WSRequest request =  new WSRequest("method name here");
request.addProperties("property1Name",property1);
request.Send();

requestSend()将返回一个包含从Web服务接收的对象的SoapObject。