0
votes

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
Can you post the definition of the User class?carlosfigueira
Have you made the [DataMember] attributes to your User properties?user2315834

2 Answers

0
votes

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)]
0
votes

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

 <requestLimits maxAllowedContentLength ="<length>" />