开发者

Is it possible to respond to request from another method that the one defined in [OperationContract]?

开发者 https://www.devze.com 2023-01-01 18:10 出处:网络
as in the title, i have: [ServiceContract] public interface IService { [OperationContrac开发者_如何学Pythont]

as in the title, i have:

[ServiceContract]
    public interface IService
    {
        [OperationContrac开发者_如何学Pythont]
        [WebGet(UriTemplate="abc")]
        Stream GetResponse(Stream in);
    }

    public class Service : IService
    {
        public Stream GetResponse(Stream in)
        {
           some_function()
        }   
    }

is it possible to pass a request context to some other function that will respond to the request?


Yes, within some_function you can access the current WCF OperationContext via the static Current property which will give you full access to everything about the request. Or, better yet, you can design some_function to accept an OperationContext parameter and then it doesn't have to pull it out of thin air itself which actually makes for better testability.

In addition to the context, you will also need to take and return the Stream instances from some_function if it intends to act on them.

So your some_function might look something like this:

public Stream GetResponse(Stream in) 
{ 
    return some_function(OperationaContext.Current, in);
} 
0

精彩评论

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