2011-03-18 115 views
3

我有一个从服务器下载内容的WCF客户端。获取内容WCF响应类型

服务合同是;

[OperationContract] 
     [WebGet(
       UriTemplate = "/my/service/url/{method}/{filename}?tradeId={tradeId}&docType={docType}&language={language}&version={version}", 
       ResponseFormat = WebMessageFormat.Json, 
       BodyStyle = WebMessageBodyStyle.Bare)] 
     Stream GetDocument(string method, string filename, string tradeId, string docType, string version, string language); 

返回类型是Stream。我所做的只是将该流写入文件并且它可以工作。

现在,我想对此进行修改。我想知道下载文档的MIME类型。我知道它在服务器上正确设置。我只需要检索它。

我几乎没有WCF的经验,也不知道该怎么做。有人可以让我知道吗?

非常感谢

回答

5

你必须可以访问OperationContextWebOperationContext。为了达到这个目的客户使用OperationContextScope

using (var scope = new OperationContextScope((IContextChannel)proxy)) 
{ 
    Stream document = proxy.GetDocument(...); 
    string contentType = WebOperationContext.Current.IncomingResponse.ContentType; 
} 
+0

非常感谢。这个对我有用 :) – Kevin 2011-03-18 16:38:05