在iis 7.5中wcf rest service json响应的未知文件类型 [英] Unknown file type for wcf rest service json response in iis 7.5
问题描述
我在wcf rest服务中遇到问题,返回json响应。在我的本地IIS-Webserver上运行Visual Studio 2010中的服务工作得很好。
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.
但是现在我在Windows Server 2008上使用相同的web.config运行相同的服务R2与IIS 7.5和我通过
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
*http://localhost/EchoService/EchoService.svc/echo/123
它不会返回json结果,而是一个带有未知文件类型的下载对话框,其中包含json结果。
it doesn´t return the json result but a download dialog with an unknown file type with the json result in it.
首先我认为问题是,网络服务器不知道json mime类型所以我添加了:
First I thought the problem is, that the webserver does not know the json mime type so I added it with:
扩展名: .json
MIME-类型: application / json
MIME- Type: application/json
条目类型: 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?
这是我的web.config:
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);
}
和服务实施:
public class EchoService: IEchoService
{
public string EchoMessage(string message)
{
return "Hey Buddy. You said: " + message + "!";
}
}
我希望你能帮助我。谢谢!!!
I hope you can help me. Thanks!!!
推荐答案
可能是浏览器中的预期行为。它认为Json是一种下载类型。为避免这种情况,您应该更改内容类型以响应text / plain。 此处讨论了如何执行此操作。
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.
这篇关于在iis 7.5中wcf rest service json响应的未知文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!