Scenario
The scenario is pretty simple. A third party REST service, GetCalledNumbers, that provides the list of the recent called numbers needs to be exposed. To meet the customer’s privacy policies it’s been required to mask the dialed phone numbers.
To achieve these requirements I created a REST façade service that virtualizes the third party one. Then I built a custom endpoint behavior that replaces the phone numbers with asterisks except the last 4 digits.
In this demo the inspector has been positioned at the client side so the IClientMessageInspector interface has been implemented. It’s not the intent of this post to describe how to build a message inspector, here, you can find a complete example.
Register
To use the custom component, first it has to be registered.
The register procedure is pretty straightforward:
- Drop Codit.Demo.Sentinet.Extensions.dll in the bin directory of both Repository and Nodes applications (for Sentinet Nodes you might need to create empty bin directory first).
- Register/add behavior extension in web.config files of both Repository and Nodes applications
<behaviorExtensions>
<add name=”jsonMask” type=”Codit.Demo.Sentinet.Extensions.Formatting.JsonFormatterEndpointBehaviorExtension, Codit.Demo.Sentinet.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9fc8943ef10c782f”/>
</behaviorExtensions>
- Then you can add this endpoint behavior in the Sentinet Console shared behaviors (for the future re-use of this shared component between virtual services):
<behavior name=”JsonFieldMask”><jsonMask toBeBlurred=”PhoneNumber” /></behavior>
- Now you can apply this shared endpoint behavior to the inbound endpoint(s) of the virtual service.
Using the Sentinet Administration console, first create a new behavior:
Then apply it to the virtual service.
Test
For testing the virtual service I used postman to send a GET request to my virtual API.
During this test I enabled the full transaction recording so that in the Monitor tab I can access to the content transmitted and check the result of the message inspector.
Conclusion
Message inspectors are the most used extensibility points of the WCF runtime. In this article we saw how to set-up and use custom / third party components in Sentinet. In the next post I will discuss about the Sentinet’s routing feature and how to build a custom router.
Cheers,
Massimo
Subscribe to our RSS feed