我正在尝试将值从 android 传递到 aspx Web 服务。但是 Web 服务不采用以下代码中传递的 32。
Request.addProperty("SayHello", "32");
任何帮助将不胜感激。
我完整的android代码如下
package com.example.fp1_webservicedropdown;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;
public class MainActivity extends Activity {
TextView result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
result = (TextView) findViewById(R.id.textView2);
final String NAMESPACE = "http://sample.com/";
final String METHOD_NAME = "SayHello";
final String SOAP_ACTION = "http://sample.com/SayHello";
final String URL = "http://myLoclalIP/HellowWorld/Service1.asmx";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("SayHello", "32");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try {
aht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();
result.setText("The web service returned " + resultString);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
我的网络服务代码如下:
[WebService(Namespace = "http://sample.com/")]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public String SayHello(int a)
{
int passingValue = 8 + a;
String aTemp=passingValue.ToString();
return aTemp;
}
}