2011-08-04 42 views
1

我使用WCF REST模板40(CS)创建了一个简单的REST服务,它工作得很好。只有响应使用“application/json”作为内容类型的问题,但我需要“text/plain”。WCF REST WebService内容类型错误

该问题已在博客文章中解释过,但由于模板我没有使用.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> 

回答