Thursday, August 26, 2010

Web Service with json

This is my first blog where we use to explain some issue which is face in my real life environment (DotNet).
Hello friend,
i want to communication between device(mobile) and server side, so that our team is decided to work on web service(dot net) as a mediator.
but in device side, used json response instead of xml and dot net web service return predefine xml response which is take more time to extract json string from the web service.
Response in web service with string tag:
        {'GenInfo':[{'type':'Response', 'appname':'iBehavior'} ],'Registration':[{ 'categorylist':['catid':'value', 'category':'value', 'couponcount':'value']} ]}

but i want the response in  json only
i.e. {'GenInfo':[{'type':'Response', 'appname':'iBehavior'} ],'Registration':[{ 'categorylist':['catid':'value', 'category':'value', 'couponcount':'value']} ]}

so  that we write the json response directly to the browser

Below code help to read the json response directlly without xml tag.
Check the below test sample and let me know your comment.

//1.Test web service.
[WebMethod(CacheDuration = 30, Description = "This is a testing purpose only for dot net developer.")]
public void TestWebServiceJson()
String sJSonResponce = “{‘GenInfo’:[{'type':'Response', 'appname':'iBehavior'} ],’Registration’:[{ 'categorylist':['catid':'value', 'category':'value', 'couponcount':'value']} ]}”;
Context.Response.ContentType = “text/plain”;

Ashish Jiwane