开发者

What should we take care of when passing json to a WCF webHTTP service?

开发者 https://www.devze.com 2023-01-18 12:52 出处:网络
I\'m running into a lot of troubles trying to do a post request from my jQuery code passing a JSON object to my webservice method.

I'm running into a lot of troubles trying to do a post request from my jQuery code passing a JSON object to my webservice method.

I know this question might seem to be pointless, but I wanted to know how WCF recognize a JSON string and converts it into a object. What should we configuring to have the warranty that it should work?

I followed s开发者_开发问答everal pages and blog posts like this but I can't get it working. Every time the service code is hit, the parameter comes as a null object!

Any advise, tips, inner workings that we should be aware of ?


Why not pass in the json data as a string to your web service, and then on the other side you can deserialize, but how to do that depends on your version of .net. You may want to look at what is available at http://json.org.


var json_object = json_string.evalJSON()

that's for prototype sorry.... with jQuery it's:

var json_object =jQuery.parseJSON(json_string)


Take a look at this page http://www.codemeit.com/wcf/wcf-restful-pox-json-and-soap-coexist.html

Couple of things to keep in mind. The below given section of web.config is mentioned in the page mentioned above.

In your web.config, in the behavior section -----> This should be

For your data contract, the methods that you are going to call using Jquery with Json strings should have the WebInvoke attribute set with RequestFormat and ResponseFormat set as WebMessageFormat.Json.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号