Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
Calling a REST Based JSON Endpoint with HTTP POST and WCF - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, MonoTouch for iPhone, MonoDroid for Android, and Windows Azure.

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

Calling a REST Based JSON Endpoint with HTTP POST and WCF

Note: I always forget this stuff, so I'm putting it my blog to help me remember it.

Calling a JSON REST based service with some params isn't that hard.  I have an endpoint that has this interface:

        [WebInvoke(UriTemplate = "/Login",
            Method="POST",
            BodyStyle = WebMessageBodyStyle.Wrapped,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json )]
        [OperationContract]
        bool Login(LoginData ld);

The LoginData class is defined like this:

    [DataContract]
    public class LoginData
    {
        [DataMember]
        public string UserName { get; set; }
        [DataMember]
        public string PassWord { get; set; }
        [DataMember]
        public string AppKey { get; set; }
    }
 

Now that you see my method to call to login as well as the class that is passed for the login, the body of the login request looks like this:

{ "ld" : {  "UserName":"testuser", "PassWord":"ackkkk", "AppKey":"blah" } }

The header (in Fiddler), looks like this:

User-Agent: Fiddler
Host: hostname
Content-Length: 76
Content-Type: application/json

And finally, my url to POST against is:

http://www.something.com/...../someservice.svc/Login

And there you have it, calling a WCF JSON Endpoint thru REST (and HTTP POST)
Posted: Jan 16 2011, 06:00 AM by Wallym | with no comments
Filed under: , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)