2011-08-04 5 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> 

答えて

4

あなたはWCF RESTサービスから任意のコンテンツを返すようにしたい場合は、生のプログラミングモデルを使用する必要があります - http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx 。使用したテンプレートは、サービスルートを使用してエンドポイントを定義するため、すべてセットアップされています。今度は、Streamパラメータを返す操作を定義し、操作で適切なコンテンツタイプを設定する必要があります。WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";

関連する問題