Get Content WCF Response Type

I have a WCF client that downloads content from a server.

service contract:

[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. I just simply write this stream to a file and it works.

Now I want to make changes to this. I want to know the MIME type of the loaded document. I know that it is installed correctly on the server. I just need to restore it.

I have little experience with WCF and I don’t know how to do this. Can anyone tell me?

Many thanks

+3
source share
1 answer

You must access OperationContextor WebOperationContext. To achieve this on the client, use OperationContextScope:

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

All Articles