0

我创建了一个 Web 服务来测试通过 ksoap2 传递的参数。我认为这似乎是一个非常简单的过程,但我显然缺少一些简单的东西。Web 服务只是返回传递给它的整数。当我执行下面的代码时,它返回数字 0 而不是 1。

    private static String SOAP_ACTION = "http://tempuri.org/TestParams";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "TestParams";
private static String URL = "http://services.lockrem.com/WebService.asmx?WSDL";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("RoundId", 1);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
    } catch (Exception e) {
        e.printStackTrace();
    }

    SoapObject result = (SoapObject)envelope.bodyIn;

注意:我已经使用 .net 网页对此进行了测试,它按预期返回数字 1。Web 服务不是这里的问题。

这是网络服务。

    [WebMethod]
public int TestParams(int RoundId)
{
    return RoundId;
}

感谢您的任何帮助。

4

2 回答 2

0

免责声明:每当我尝试使用 kSoap2 与 .NET Web 服务通信时,我通常最终都会做很多摆弄。我的意思是字面意思:我用Fiddler2设置了一台 Windows 机器,并将它用作失败请求和工作参考请求的代理,所以我实际上可以看到出了什么问题。我强烈建议您在尝试做一些不平凡的事情时立即做类似的事情。

也就是说,在你的情况下,这可能就足够了

envelope.dotNet = true;
于 2012-04-08T19:24:39.613 回答
0

最后尝试删除 WSDL

private static String URL = "http://services.lockrem.com/WebService.asmx";

另外尝试使用它来获得响应:

Object response = envelope.getResponse();

代替SoapObject result = (SoapObject)envelope.bodyIn;

已编辑

这有效:

public class MainActivity extends Activity {

private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "TestParams";
private static String URL = "http://services.lockrem.com/WebService.asmx";
private TextView tv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tv = (TextView)findViewById(R.id.tv);
    HttpTransportSE transport = new HttpTransportSE(URL);
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("RoundId", 1);
    SoapSerializationEnvelope envelope =
        new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    try {
        transport.call(NAMESPACE + METHOD_NAME, envelope);
        Object response = envelope.getResponse();
        tv.setText(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

希望能帮助到你。

于 2012-04-08T22:22:01.213 回答