Reputation: 593
Im trying to pass in an int value to the web service and expecting for a reply. But im only getting the value on the web service instead. I mean it doesn't take in my input value. The android code is as follows:
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();
}
}
}
The web service code is as follows:
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;
}
}
}
it simply returns The web service returned 8 when i run through android. Insted of giving The web service returned 40. Any help is greatly appreciated.
Upvotes: 1
Views: 471
Reputation: 10856
Web service or a Web URL is a text based format. it don't identify data type. it just accept text.. so you have to pass as a String and from the web service code you have to convert it in int.
use this in web service
public int SayHello(String abc)
{
// convert abc to int
int t = 8 + converted int;
return t;
}
Upvotes: 1