[英]Get content Type of WCF response
我有一个从服务器下载内容的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没什么经验,也不知道怎么做。 有人能告诉我吗?
非常感谢
您必须能够访问OperationContext
或WebOperationContext
。 要在客户端上实现这一点,请使用OperationContextScope
:
using (var scope = new OperationContextScope((IContextChannel)proxy))
{
Stream document = proxy.GetDocument(...);
string contentType = WebOperationContext.Current.IncomingResponse.ContentType;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.