C# 获取WCF响应的内容类型
我有一个从服务器下载内容的WCF客户端 服务合同为:C# 获取WCF响应的内容类型,c#,wcf,http,mime,C#,Wcf,Http,Mime,我有一个从服务器下载内容的WCF客户端 服务合同为: [OperationContract] [WebGet( UriTemplate = "/my/service/url/{method}/{filename}?tradeId={tradeId}&docType={docType}&language={language}&version={version}", ResponseFormat
[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);
返回类型是流。我所做的只是将该流写入一个文件,然后它就可以工作了
现在,我想对此进行修改。我想知道下载文档的MIME类型。我知道它在服务器上设置正确。我只需要找回它
我对WCF几乎没有经验,也不知道如何做到这一点。有人能告诉我吗
非常感谢您必须访问
OperationContext
或WebOperationContext
。要在客户端上实现这一点,请使用OperationContextScope
:
using (var scope = new OperationContextScope((IContextChannel)proxy))
{
Stream document = proxy.GetDocument(...);
string contentType = WebOperationContext.Current.IncomingResponse.ContentType;
}