0

我正在编写一个使用 KSOAP 与 Web 服务通信的 Android 应用程序。Web 服务和 Android 应用程序之间的连接正在工作,因为我可以调用 Web 服务并获取返回值 (hello)。但是,如果我尝试通过 .addProperty 将应用程序中的名称赋予 Web 服务,则 Web 服务将返回一个空对象。

这是我的代码:

主要活动:

private final String NAMESPACE_Local = "http://test.com/";  
    private final String URL_Local = "http://168.185.226.21:7001/myTest/myTestWebServiceService";
  private final String SOAP_ACTION_Local = "Hello_Action_Extend";
   private final String METHOD_NAME_Local = "hello_extend";

    public void LocalServer(View view)
    {
        TextView text = (TextView) findViewById(R.id.update_text);

        SoapObject request = new SoapObject(NAMESPACE_Local, METHOD_NAME_Local);
        request.addProperty("name", "Christian");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_Local);

        try {
            androidHttpTransport.call(SOAP_ACTION_Local, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            Log.i("myApp", response.toString());


            text.setText(response.toString());

        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this,"Device or service offline",Toast.LENGTH_LONG).show();
        }
    }

网络服务器:

package com.test;

import javax.jws.*;

@WebService
public class myTestWebService {

    @WebMethod(action="Hello_Action") //that method works
    public String hello() {
        return "hello";
    }

    @WebMethod(action="Hello_Action_Extend")
    public String hello_extend(String name) //that works also, but it is giving back "hello null"
    {
        return "hello "+name;
    }
}

我希望你能帮帮我!

4

1 回答 1

1

尝试更换:

request.addProperty("name", "Christian");

为了:

request.addProperty("name",ElementType.STRING_CLASS, "Christian");

以及对以下内容的回应:

SoapObject reponse=(SoapObject)envelope.getResponse();
response.getProperty("name");

API 肥皂对象

于 2013-03-05T14:01:16.427 回答