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