I have a situation where I have to create a service A (kind of a Proxy service) which will in turn calls another service B (the real service). The client C will only know the service A. Service A will log the call and would just kind of forward the request to B. After it gets a reply from B, A logs the response and sends it back to the client C. To achieve this scenario I have seen many examples but nothing seems to work. I do have a few limitations. I can't add the reference of the service B inside service A. I also can't create service references. Services A and B are totally different and they don't know each other.
----> ---->
C A B
<---- <----
In A, inside BeforeSendRequest() of IClientMessageInspector, I had updated the request.Headers.To to the URI of the service B. But this method never gets called. I have also attached an EndPointBehavior to it.
My sample code below. I am using .Net 4.5.
SimpleMessageInspector class
public class SimpleMessageInspector: IClientMessageInspector
{
public object BeforeSendRequest(request, channel)
{
request.Headers.To = new Uri("http://localhost:8087/B");
}
}
App.Config ...
<services>
<service name="A" behaviorConfiguration="AServiceEndpointBehavior">
<endpoint ...
<endpoint ...
<host>
<baseAddresses>
<add baseAddress="http://localhost:8083/A">
</baseAddresses>
</host>
</service>
<services>
<behaviors>
<endpointBehaviors>
<behavior name="AServiceEndpointBehavior">
<simpleBehaviorExtension/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailsInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="simpleBehaviorExtension" type="A.SimpleBehaviorExtensionElement, A" />
</behaviorExtensions>
</extensions>
...
In the end, the service A is never calling the service B. Where am I going wrong here? Your help is appreciated.
By the way, there are few questions here in SO, but nothing seemed to work for my case.