Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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());
             }
     }


}

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
318 views
Welcome To Ask or Share your Answers For Others

1 Answer

Instead of

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

try using

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...