如何使用kso​​ap2传递参数给web服务? [英] How to pass parameter to a webservice using ksoap2?

查看:131
本文介绍了如何使用kso​​ap2传递参数给web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse IDE开发一个Android应用程序。我试图连接到一个.NET Web服务。我使用kso​​ap2 2.3版

I'm using Eclipse IDE to develop an android app. I'm trying to connect to a .net webservice. I'm using ksoap2 version 2.3

当我打电话不带参数的WebMethod的,它工作正常。当我来到参数传递给将WebMethod,我得到空(在调试web服务,我发现),我得到一个空从客户端code将WebMethod。

When I'm calling a webmethod with no parameters, it works fine. When I come to pass a parameter to the webmethod, I get null (while debugging the webservice I discovered that) and I get a null from the webmethod in the client side code.

code:

package com.examples.hello;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloActivity extends Activity {
    /** Called when the activity is first created. */
 private static final String SOAP_ACTION = "http://Innovation/HRService/stringBs";

 private static final String METHOD_NAME = "stringBs";

 private static final String NAMESPACE = "http://Innovation/HRService/";
 private static final String URL = "http://196.205.5.170/mdl/hrservice.asmx";
 TextView tv;

 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     tv=(TextView)findViewById(R.id.text1);
     call();

 }

 public void call()
 {
         try {

          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
          //PropertyInfo PI = new PropertyInfo();

             //request.addProperty("a", "myprop");

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

             envelope.dotNet=true;
             envelope.encodingStyle = SoapSerializationEnvelope.XSD;


             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

             androidHttpTransport.call(SOAP_ACTION, envelope);

             Object result = (Object)envelope.getResponse();


             String results = result.toString();
             tv.setText( ""+results); 
         } catch (Exception e) {
             tv.setText(e.getMessage());
             }
     }


}

为什么我得到空的反应,我该如何使用kso​​ap2参数传递到一个web服务?

Why do I get the null response, how do I pass a parameter to a webservice using ksoap2?

推荐答案

    request.addProperty("a", "myprop"); 

尝试使用

    request.addProperty("arg0", "myprop");         

我不是一个期望在ksoap2但我pretty的肯定,这设置第一个参数的值,以Web服务的功能。完美地为我工作。

I'm not an expect on ksoap2 but i'm pretty sure this sets the value of the first parameter to your web service function. Has worked perfectly for me.

这篇关于如何使用kso​​ap2传递参数给web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆