WCF Json returns null values for DataMember elements

I have a ws working ok when I tried it using a browser, I mean, all te correct values are returning.

But when I try to do it from my client APP using POST method, it doesn't matter what the server does, the client get nulls values.

This is my returning class:

[DataContract]
public class ResponseModel
{
    [DataMember(Name = "exito", Order = 0)]
    public bool Exito { get; set; }
    [DataMember(Name = "logout", Order = 1)]
    public bool LogOut { get; set; }
    [DataMember(Name = "frase", Order = 2)]
    public String Frase { get; set; }
}

And this is my servicecontract

[ServiceContract]
public interface IService1
{


    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "HelloWorld")]
    ResponseModel HelloWorld();
}

Answers


As you haven't posted your implementation of ResponseModel HelloWorld(); and how you are making request so I will try to make guess!

If you are posting some data to your service, you need to make it in XML or JSON for the method of POST. For this change your ServiceContract like this:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "HelloWorld")]
    ResponseModel HelloWorld();
}

I have added RequestFormat = WebMessageFormat.Json if you want to make request in JSON. For XML make it RequestFormat = WebMessageFormat.XML.

Now when you make request, then add data in JSON/XML. If you can post your request format then more appropriate suggestions can be made. For sending data in POST request, you have to set request header Content-Type: application/json; charset=utf-8. I hope this will help.


Need Your Help

PermGen space issue with Glassfish/Hibernate

java memory-leaks classloader glassfish-3 permgen

I'm running a GWT+Hibernate app on Glassfish 3.1. After a few hours, I run out of Permgen space. This is without any webapp reloads. I'm running with –XX:MaxPermSize=256m –XmX1024m.

Yeoman inside ExpressJS

node.js angularjs express yeoman

I'd still like to try to get an example running w/ Yeoman and Express.