1
我试图将一个int值传递给Web服务并期望得到答复。但即时消息只取得了Web服务的价值。我的意思是它不包含我的输入值。 Android的代码如下:Web服务不接受从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://localip/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);
System.out.println(resultString);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Web服务代码如下:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
namespace HellowWorld
{
[WebService(Namespace = "http://sample.com/")]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int SayHello(int a)
{
int t = 8 + a;
return t;
}
}
}
它只是返回Web服务返回8,当我通过Android上运行。没有给予网络服务返回40. 任何帮助,非常感谢。
我需要什么样的变化,使Web服务代码?感谢您的及时回复 – Kasanova
你必须从android代码传递字符串,并在一个web服务代码接受字符串,并在整数转换.. –
你能提供下面的示例代码行。 – Kasanova