Reputation: 745
I got issue in my wcf service library because I already set the webMessegeFormat
to JSON
format,
but instead it returns the XML
format. How can I fix this issue? Am i missing something?
Thank you so much in advance for those who will help :)
Here is my code:
public class Service : iService
{
[WebInvoke(Method="GET",
RequestFormat = WebMessageFormat.Json,
UriTemplate="{id}/{name}/{age}/{sex}/{address}")]
public Response Transaction(string id, string name, string age, string sex, string address)
{
return new Response()
{
ID = id,
Name = name,
Age = age,
Sex = sex,
Address = address
};
}
}
public class Response
{
public string ID { get; set; }
public string Name { get; set; }
public string Age { get; set; }
public string Sex { get; set; }
public string Address { get; set; }
}
Here is my app config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfEServiceLibrary.Service">
<endpoint address="http://phws13:8732/WcfServiceLibrary/"
binding="webHttpBinding"
contract="WcfServiceLibrary.iService">
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Upvotes: 0
Views: 82
Reputation: 5233
do you need to set the ResponseFormat
to WebMessageFormat.Json
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "{id}/{name}/{age}/{sex}/{address}")]
Upvotes: 1