hi,
Json object is returned to a webservice which gets the i/p as
[OperationContract(Name = "Create")]
[WebInvoke(UriTemplate = "/Create/Data", Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json)]
bool CreateCustomer(StringBuilder objCustomer);
//in my service file im deserializing the i/p obj to my class object and inserting
public bool Create(StringBuilder strObj)
{
JavaScriptSerializer js = new JavaScriptSerializer();
Customer custObj = js.Deserialize<Customer>(strObj.ToString());
bool Inserted = false;
// connection established and data is put into it
from im asp.net client the obj is serialized to json format and it can be inserted into my DB but from android, the JSON object which they are sending could not be recognised by my service.. but the response to them goes as "OK 200" ..
the android code is
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
String URL ="http://10.242.48.54/restinsert/Service1.svc/Create/Data";
try{
HttpPost post = new HttpPost(URL);
json.put("CNo",200);
json.put("CName","addme");
StringEntity se = new StringEntity(json.toString());
se.setContentType("application/json; charset=utf-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json; charset=utf-8"));
post.setHeader("Accept","application/json");
post.setHeader("Content-type","application/json; charset=utf-8");
String ss= post.toString();
response = client.execute(post);
created a new class for serialize and deserialize
public class Json
{
public string JsontoString(string obj)
{
JavaScriptSerializer js = new JavaScriptSerializer();
StringBuilder sb = new StringBuilder();
js.Serialize(obj, sb);
return sb.ToString();
}
public string StringtoJson(string obj)
{
JavaScriptSerializer js = new JavaScriptSerializer();
Customer custObj = js.Deserialize<Customer>(obj.ToString());
return custObj.ToString();
}
}
}