I´m facing a problem in my wcf rest service returning a json response. Running the service in Visual Studio 2010 on my local IIS- Webserver worked perfectly.
But now I´m running the same service with the same web.config on Windows Server 2008 R2 with IIS 7.5 and when I´m calling the service via
*http://localhost/EchoService/EchoService.svc/echo/123
it doesn´t return the json result but a download dialog with an unknown file type with the json result in it.
First I thought the problem is, that the webserver does not know the json mime type so I added it with:
Extension: .json
MIME- Type: application/json
Entry type: local
But it didn´t solve the problem. Can you please tell me why it is returning the result as a file and doesn´t know the file type?
Here´s my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="wcf_iis_proto_1.EchoService">
<endpoint address="" binding="webHttpBinding" contract="wcf_iis_proto_1.IEchoService" behaviorConfiguration="webEcho" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webEcho">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And here is my service contract (left out using and namespace):
public interface IEchoService
{
[OperationContract]
[WebGet(UriTemplate = "/echo/{message}", ResponseFormat = WebMessageFormat.Json)]
string EchoMessage(string message);
}
and service implementation:
public class EchoService: IEchoService
{
public string EchoMessage(string message)
{
return "Hey Buddy. You said: " + message + "!";
}
}
I hope you can help me. Thanks!!!
Might be it is expected behavior in your browser. It considers Json as a type to download. To avoid this you should change content type in response to “text/plain”. Here was discussed how to do this.