0

Here is my service method signature:

    [OperationContract]
    [System.ServiceModel.Web.WebInvoke(UriTemplate = "/RegisterUser", Method = "POST")]
    void RegisterNewUser(User user);

Also Type User have DataContract attribute on class and DataMember attributes on its properties

and here is how I am calling the service method:

 String data = "{\"user\":{\"__type\" : \"User:#PingMe\",\"EmailID\": \"[email protected]\",\"RegistrationID\": \"sdfhjklsdgkdfjgklgdjfklg\"}}";  
        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:2443/NotificationService.svc/RegisterUser");
        httpWebRequest.Method = "POST";
        byte[] bytes = Encoding.UTF8.GetBytes(data);
        httpWebRequest.ContentLength = bytes.Length;
        httpWebRequest.ContentType = "text/json; charset=utf-8";
            httpWebRequest.KeepAlive = false;
        Stream requestStream = httpWebRequest.GetRequestStream();
        requestStream.Write(bytes,0,bytes.Length);
        requestStream.Close();


        HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

It call the service method succesfully, but in service method's user parameter user.EmailID and User.RegistrationID always come 'NULL'

Any Idea what I am missing here?

Do I need to set RequestFormat property as WebMessageFormat.JSON? in OperationContract attribute?

Thanks

2
  • 1
    Can you post the definition of the User class? Commented Nov 28, 2011 at 14:31
  • Have you made the [DataMember] attributes to your User properties? Commented Apr 24, 2013 at 13:47

2 Answers 2

0

Change this

httpWebRequest.ContentType = "text/json; charset=utf-8";

TO this:

httpWebRequest.ContentType = "application/json; charset=utf-8";

and this:

[System.ServiceModel.Web.WebInvoke(UriTemplate = "/RegisterUser", Method = "POST")]

to this:

[System.ServiceModel.Web.WebInvoke(UriTemplate = "/RegisterUser", Method = "POST", BodyStyle=WebMessageBodyStyle.WrappedRequest,
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json)]
Sign up to request clarification or add additional context in comments.

Comments

0

in your Server Increase MaxpostSize property i dont have much knowledge on IIS but i think it will work for you

 <requestLimits maxAllowedContentLength ="<length>" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.