I'm trying to send a json object from my android activity to my asp.net web service, by the following code.
//This is Category.java
JSONObject json=new JSONObject();
try
{
CallSoap cs=new CallSoap();
String name="Ramu";
String username="ramu@gmail.com";
String password="welcome";
json.put("name", name);
json.put("username",username);
json.put("password", password);
String resp=cs.demo(json);
Log.d("Response from server",resp);
}
catch(Exception ex)
{
ex.printStackTrace();
}
//This is callsoap.java
public String demo(JSONObject a)
{
public final String SOAP_ACTION5= "http://tempuri.org/demo";
public final String OPERATION_NAME5= "demo";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://tn.selevanta.com/Convert.asmx"
SoapObject request=new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME5);
PropertyInfo pi=new PropertyInfo();
pi.setName("a");
pi.setValue(a);
pi.setType(JSONObject.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION5, envelope);
response = envelope.getResponse();
}
catch(Exception ex)
{
response=ex.toString();
}
return response.toString();
}
I don't know what code should be written in my Convert.cs file in the server. I need to write a function in Convert.cs named demo. Then the json object from my android activity should be sent over to this demo function in Convert.cs. Upon receiving the json object at my Convert.cs file, I need to parse the json data from the json object received. So that the name, username, password from the json data should be saved to my sql server database. I know the coding for saving the data into the sql server database, but I don't know how to receive json object to my demo function and parse the json data available in the json object. I have also written another Person.cs file which contains the following data.
public class Person
{
public string name { get; set; }
public string username { get; set; }
public string password { get; set; }
}
This is a portion of code in Covert.cs file
[System.Web.Services.WebMethod()]
public String demo(
{
return "success";
}