我想從android傳遞一個值到aspx web服務。但是,Web服務不採取在下面的代碼中傳遞的32。Request.addProperty(「SayHello」,「32」);不通過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();
}
}
}
我的web服務代碼如下:
[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;
}
}
印在服務器端有什麼價值?我的意思是你有任何的logcat或控制檯打印value.Kindly共享 – curious
@curious我已經加入上面的web方法代碼。因此,它只能打印8. – Kasanova