I have to add header to wcf service call.
I've implemented it this way:
var client = new ServiceReference1.HeaderConsumeClient("NetTcpBinding_IHeaderConsume");
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
Guid apiKey = Guid.NewGuid();
MessageHeader<Guid> mhg = new MessageHeader<Guid>(apiKey);
MessageHeader untyped = mhg.GetUntypedHeader("apiKey", "ns");
OperationContext.Current.OutgoingMessageHeaders.Add(untyped);
var res = client.GetData(1);
Console.WriteLine(res);
}
But i'd like to make general solution without such boilerplate code at every service call.
The most common way, i think - is to make my own TT4 template and wrap every call in generated proxies.
But before it will be done i want to know, is there a some other ways to override or decorate wcf generated classes methods?
For example - i can use unity and register implementation of this service interface and add interceptor to all calls to this instance. But it looks a bit overcomplicated.
Aucun commentaire:
Enregistrer un commentaire