Thursday, November 4, 2010

using WSO2 ESB to mediate WCF Service - Part 2

In previous post, I demonstrated how to use Pass Through Proxy to mediate a basic WCF Service which is having GetData and GetCustomTypeData methods. In part 2, We will try to add UsernameToken security at WSO2 ESB level. 

Updating Service Implementation:
Right now, I don't know how to use mediator to remove security header from soap envelop before sending it to the real service. I tried using Transformation > Header mediator but it didn't worked for me, so I used WCF Service side wrok around here. Please let me know how to do that, if some of you may know?
  • Open Service1.svc.vb and add following attribute to Service1 class:
<servicebehavior(validatemustunderstand:=false)> _
Securing wso2 esb service:
  • Login to esb website, and go to Services > List and click on WCFService
  • Click on Security
  • Select "Yes" for Enable Security and Select first option "UsernameToken"
  • Click on next and check the check box "Admin"
  • You will be redirected to service dashboard. 
  • That's it.
Updating client to include security:
  • Install WSE 3.0 and add reference the wse 3.0 dll from it's installation directory to client project
  • Open Reference.vb from your client code, and change your web service class inherited from Inherits Microsoft.Web.Services3.WebServicesClientProtocol
  • Rebuild the client project again to make sure we haven't broken anything
  • Open Module1.vb and add following lines before calling GetData:
    Dim client As New localhost.WCFService
    Dim U As New UsernameToken( _
     "admin", _
     "admin", _
    ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy()
This way we can use wso2 esb to secure wcf service implemented using basicHttpBinding. Advantages here is, we are using separate GUI base server for securing wcf service which is too easy to maintain. 
It is obvious that this example is very basic and it is just an exercise to add security in wcf services implemented using basicHttpBinding.

Next steps will be to add some real life use cases that makes presence of esb more appropriate and not only for security.

Pelase provide your thoughts on wso2 esb and wcf integration and if you are having trouble integrating with the same, you can drop me and email or post a comment here.

No comments:

Post a Comment

Please add your valuable comments about this post if it helped you. Thanks