Tuesday, October 25, 2011

Step 5 : Pass multiple body parameters in wcf rest



How pass multiple body parameters in wcf rest

using webinvoke method(Post or PUT)








Even If you have blank namespace  [DataContract(Namespace = "")] you have to put 
xmlns="" in the request body ... ( see the pictures below )
Whithout xmlns="" in the request body , problems can appear 






  [OperationContract]
        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Xml,
            RequestFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "testpersondatapost")]
        PersonData TestPersonDataPost(PersonData pd);


  [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; }
    }


       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;
        }
























No comments:

Post a Comment