【发布时间】:2011-08-04 11:21:49
【问题描述】:
我使用 WCF REST 模板 40(CS) 创建了一个简单的 REST 服务,它工作得很好。唯一的问题是响应使用“application/json”作为内容类型,但我需要“text/plain”。
该问题已在博客文章中进行了解释,但由于模板的原因,我没有使用 .svc 文件。所以建议的解决方案对我不起作用。
我的服务合同:
[ServiceContract]
public interface ICouchService
{
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/", Method = "GET")]
ServiceInformation Hello();
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/piclib/{id}")]
CouchDocument GetDocument(string id);
}
web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
【问题讨论】:
标签: wcf web-services rest service