0

This is my first question here so pardon me if I am not following the full guidelines.

We have micro services architecture and nearly 15 .Net Services all accessible via REST Api. (Combination of WCF and WebAPI).

Most of the services accept two security related headers in every http call.

The presence of such headers is done via intercepting WCF or Web API calls at present

Now we have started creating .Net based Service Client (internally using RestSharp) and make them availabel via NuGet because we want to make the integration easy.

So we now have a dilemma about how to go about passing this security related headers into each method of such Service Client.?

The options we are thinking about are

  1. Have an additional parameters in each method so that consumers of our service client can pass the security headers
  2. Have a tracing context interface injected into Service Client constructor so that each methods can inspect it and responsibility of setting the correct tracing context will be with consumers. A bit muddy as each method can be called with different values for security headers

Following is a code snippet we are thinking

            public class TestResponse
            {
            public bool Success { get; set; }
            }

            public class TestRequest
            {
            public string Name { get; set; }
            }

            public interface ITestServiceClient
            {
            TestResponse GetTest(TestRequest testRequest);
            }

            public class TestServiceClient : ITestServiceClient
            {
            private readonly Uri _serviceBaseUrl;

            public TestServiceClient(Uri serviceBaseUrl)
            {
            _serviceBaseUrl = serviceBaseUrl;
            }

           // We would need to pass the required header as part of this method call                
            public TestResponse GetTest(TestRequest testRequest)
            {
               //RestSharp call here to actual service HTTP url            
               return new TestResponse();
            }
            }

What's the best way to achieve this?

Thanks

  • Have you looked at this: http://stackoverflow.com/questions/964433/how-to-add-a-custom-http-header-to-every-wcf-call – David Martin May 09 '17 at 10:56
  • Thanks @DavidMartin. I have looked at the url and we have got similar mechanism at the server side. But my question was more about design of the .Net Client given to our consumers who could be using console app, windows service or ASP.Net. So they are agnostic of what our service does, but need to pass some key value pair which our .Net client can pass on to service as HTTP headers. – Bhavik Suthar May 09 '17 at 13:43

0 Answers0