Is it possible to respond to request from another method that the one defined in [OperationContract]?
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);
}
精彩评论