1

I know it's possible to add a header to a WCF request, like described here: How to add HTTP Header to SOAP Client

Service1Client serviceClient = new Service1Client();
using (new System.ServiceModel.OperationContextScope((System.ServiceModel.IClientChannel)serviceClient.InnerChannel))
{
    System.ServiceModel.Web.WebOperationContext.Current.OutgoingRequest.Headers.Add("AdminGUID", "someGUID");
    serviceClient.GetData();
}

I have a use case, where I need to add such a header to all outgoing requests, and I would like to avoid wrapping every single WCF service method call in a using statement.

Is there a way to configure the ServiceSoapClient to add these headers to all requests?

Or maybe is there a way to generate a child class from the service reference, that would wrap all calls to base class, without doing it manually? A macro would be handy here...

Elo Siema
  • 31
  • 4
  • With [message inspectors](https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/message-inspectors) maybe? See also https://stackoverflow.com/questions/964433/how-to-add-a-custom-http-header-to-every-wcf-call – Bogdan May 13 '21 at 16:13
  • 1
    @Bogdan Message inspectors were exactly what I was looking for. Thank you! – Elo Siema May 13 '21 at 16:19

0 Answers0