开发者

Get content Type of WCF response

I have a WCF client that download content from the server.

the service contract is;

[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);

The return type is a Stream. What I do is simply just write that stream to a file and it works.

Now, I want to make modification on this. I want to know the MIME type of the dow开发者_开发百科nloaded document. I know it is set properly on the server. I simply need to retrieve it.

I have little experience with WCF and don't know how to do that. Can someone let me know?

Many thanks


You must get access to OperationContext or WebOperationContext. To achieve that on a client use OperationContextScope:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜