C# WebService return json -



C# WebService return json -

i need homecoming message web service bellow, has in json format. possible accomplish now?

c# code:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.services; using system.web.script.services; namespace webapplication1 { [webservice(namespace = "http://tempuri.org/")] [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)] [system.componentmodel.toolboxitem(false)] [system.web.script.services.scriptservice] public class webservice1 : system.web.services.webservice { [webmethod] [scriptmethod(responseformat = responseformat.json)] public response helloworld() { response obj = new response { message = "no fromformat recieved.", success = false }; homecoming obj; } } public class response { public string message = ""; public boolean success = false; } }

jquery code:

//contenttype: "application/json" if add together line, response undefined. $('document').ready(function () { $.ajax({ url: 'http://exampleurl.com/webservice1.asmx/helloworld', type: 'post', success: function (data) { console.log(data.responsetext); }, error: function (data) { console.log(data.responsetext); }, async: false, datatype: "json", }); });

response:

<?xml version="1.0" encoding="utf-8"?> <response xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns="http://tempuri.org/"> <message>no fromformat recieved.</message> <success>false</success> </response>

the followig statement returns json response

string json = javascriptserializer.serialize({"results":[{"id":1,"value":"abc","info":"abc"},{"id":2,"value":"xyz","info":"xyz"}); homecoming json;

c# json post

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -