Im using ksoap2 to call web .net services. The call works just fine except when I pass paramaters. The passed paramaters are always recieved as null values by the web service. I dont know what the problem is, I hope someone can help. Thanks,
My code is below please help me
package com.android.countrycode;
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.util.Log;
import android.widget.TextView;
public class CountryActivity extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://www.webserviceX.NET/GetCountryByCountryCode";
private static final String OPERATION_NAME = "GetCountryByCountryCode";
private static final String WSDL_TARGET开发者_如何学JAVA_NAMESPACE = "http://www.webserviceX.NET/";
private static final String SOAP_ADDRESS = "http://www.webservicex.net/country.asmx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
//PropertyInfo pi = new PropertyInfo();
//pi.setName("CountryCode");
//pi.setValue("AS");
//request.addProperty(pi);
//request.addAttribute("CountryName", "Portugal");
//request.setProperty(1, "Portugal");
request.addProperty("CountryCode","AS");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
textView.setText(response.toString());
System.out.println(response.toString());
}
catch (Exception exception)
{
String exceptionStr=exception.toString();
textView.setText(exceptionStr);
System.out.println(exceptionStr);
Log.i("TAG",exceptionStr);
}
}
}
May be try this...
String parameter="as";
then
request.addProperty("CountryCode",parameter);
精彩评论