Calling a REST Based JSON Endpoint with HTTP POST and WCF - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

News

Please goy buy 3-4 copies of my book on MonoTouch titled "Professional Android Programming with Mono for Android for .NET/C# Developers." They make great gifts all year round. Plus, I get about $.25 when you buy a copy.

Technical Sites

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, MonoTouch, MonoDroid, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, jQuery, jQuery Mobile, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

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)

Comments

 

Twitter Trackbacks for Calling a REST Based JSON Endpoint with HTTP POST and WCF [morewally.com] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Calling a REST Based JSON Endpoint with HTTP POST and WCF         [morewally.com]        on Topsy.com

December 28, 2010 4:23 AM
 

Dew Drop – December 28, 2010 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop – December 28, 2010 | Alvin Ashcraft's Morning Dew

December 28, 2010 8:04 AM
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems