I have looked and around and seen that it is possible to return objects serialized into Json from a WCF web service. Does anyone know how I can do this?
Thanks
I have looked and around and seen that it is possible to return objects serialized into Json from a WCF web service. Does anyone know how I can do this?
Thanks
You will have to add attribute to the service like this
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
ObjectName YourMethodName();
Yes it is possible you can set automaticFormatSelectionEnabled to true standardEndpoint of webHttpEndpoint in web.config like
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
And you need to add http header for json response to your client
using (HttpClient client = new HttpClient("endpoint"))
{
HttpRequestMessage request = new HttpRequestMessage("GET", "SomeMethod");
request.Headers.Accept.AddString("application/json");
...
}