开发者

Get content Type of WCF response

开发者 https://www.devze.com 2023-02-18 18:23 出处:网络
I have a WCF client that download content from the server. the service contract is; [OperationContract]

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

精彩评论

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

关注公众号