Wednesday, October 26, 2011

Step 6 : WCF REST & FIDDLER JSON - request body


WCF REST * FIDDLER JSON - request body , headers and content type : 



  [DataContract(Namespace = "")]
    public class PersonData
    {
        [DataMember]
        public string Name { get; set; }


        [DataMember]
        public string User { get; set; }


        [DataMember]
        public string Email { get; set; }


        [DataMember]
        public string Password { get; set; }
    }




    [OperationContract]
        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "jsontestpersondatapost")]
        PersonData JsonTestPersonDataPost(PersonData pd);





       public PersonData TestPersonDataPost(PersonData pd)
        {
            var response = new PersonData
            {
                Name = pd.Name,
                User = pd.User,
                Email = pd.Email,
                Password = pd.Password
            };
            
            return response;
            // return pd;
        }


        public PersonData JsonTestPersonDataPost(PersonData pd)
        { 
            return TestPersonDataPost(pd);
        }









POST http://192.168.61.3/RestServicePost/RestServiceImpl.svc/jsontestpersondatapost HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: 192.168.61.3
Content-Length: 86


{ "pd" : { "Email":"bo@se.us" , "Name":"amab" , "Password":"egti" , "User":"brac" } } 










HTTP/1.1 200 OK
Content-Length: 99
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Wed, 26 Oct 2011 18:31:54 GMT


{"JsonTestPersonDataPostResult":{"Email":"bo@se.us","Name":"amab","Password":"egti","User":"brac"}}










1 comment:

  1. hello, nice blog.. now my question is if i want pass multiple objects like {"JsonTestPersonDataPostResult":{"Email":"bo@se.us","Name":"amab","Password":"egti","User":"brac"},{"Email":"bo@se.us","Name":"amab1","Password":"egti1","User":"brac1"},{"Email":"bo@se.us","Name":"amab2","Password":"egti2","User":"brac2"}} not 3 fix its unlimited objects in my case how to do like this? its possible?

    ReplyDelete