Thursday, November 18, 2010

DNN Module development Using Nhibernate

Hi All this is my first blog on Tricky Coders. In my last project which is in and I have used Nhibernate as the ORM which is very stable and also an open source project like DotNetNuke. So I decided to used it with DNN.
Please download latest verion of NHibernate.
  1. Nhibernate.dll -This contains the NHibernate framework
  2. Iesi.Collections.dll -Iesi.Collections.dllContains the definition of some special collections used by NHibernate
  3. Castle.Core.dll-Base library is needed by Castle.DynamicProxy2.dll
  4. Castle.DynamicProxy2.dll - This contains code to generate proxies and is used by NHibernate to make e.g. lazy load possible
  5. We need to make some modifications in the web.config to support the Nhibernate.
Getting Started with Module Development
To create my module in DotNetNuke using Nhibernate i have used 2 projects
  1. DataAccessLayer- This class library project serves the purpose to connect with database by creating the object of Session Factory.
  2. Mapping Classes- This Class Library project serves the purpose of Defining the Entites and their mapping xml files.
  3. My Actual module which refer the above Projects to talk with data base.

    You can  download this module's source and installation package from tricky coder's codeplex project

    Please let me know about your views and suggestions to improve the code.

    Hope this will help.

    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.

    using WSO2 ESB to mediate WCF Service

    In this post, I'm going to create a new WCFService with basicHTTPBinding and deploy it to IIS. I will mediate the deployed service with WSO2 ESB 3.0.0. For mediating the service, I will use "Pass Through Proxy".
    1. Pre-requisites
      1. Visual Studio 2008 or higher to create WCF Service
      2. wso2 esb 3.0.0 or higher, get it from here
    2. Install and Start  WSO2 ESB 3.0.0
      1. Extract the downloaded esb files
      2. Go to command prompt
      3. locate to bin directory of extracted esb
      4. write "wso2server.bat" and that will start the wso2 esb server after a few seconds
    3. Create a new WCF Service
      1. Start Visual Studio and go to File > New Project
        Create a new WCF Service Application from visual studio
      2. That will create a new WCF Service
      3. Open web.config and go to "system.serviceModel" element:

        <service name="xxx" behaviorConfiguration="xxxx">
            <!-- Service Endpoints -->
            <endpoint address="" binding="basicHttpBinding" contract="xxxx">    
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

        Make sure you change the endpoint element's binding attribute is having value basicHttpBinding
      4. Just Right click on the service project and click on Build Project
      5. It show you "Build Success" in status bar
      6. Right click on project again and click on publish
      7. Create a new folder called WCFServiceDeployed and select it as output directory
      8. Go to IIS and Create a new virual directory called "WCFService" and point it to WCFServiceDeployed folder
      9. right click on Service1.svc (or whatever svc file you have) and click on browse.
      10. Copy the wsdl url shown in the service page.
    4. Create Pass through proxy in wso2 esb
      1. Make sure you have wso2 esb up and running
      2. Locate your browser to https://localhost:9443/carbon
      3. use admin/admin as username/password to login to the site
      4. Click on Services > Add > Proxy Services
      5. Click on "Pass Through Service"
      6. enter "WCFService" in "Proxy Service Name" text box
      7. In "Target Url" add url of WCF Service
      8. Expand "Publish WSDL" option
      9. From the Publish WSDL drop down menu, choose "Specify Source Url"
      10. In the text box of WSDL URI, enter your published svc url suffixed with ?wsdl
      11. Expand Transport
      12. Uncheck HTTPS transport
      13. Click on create
      14. Go to Services > List
      15. Click on WCFService
      16. Copy the endpoint url
    5.  Creating Client for the newly created service in esb
      1. Start Visual studio
      2. Create a new console application project (i'm using visual basic)
      3. Right click on the project and click on add web reference
      4. enter the url of the endpoint that you get from web esb
      5. click on ok
      6. go to module1.vb
      7. Add following code:
        Dim client As New localhost.WCFService
        Dim strData As String = client.GetData(100, True)
        Dim cmpType As New localhost.CompositeType
        cmpType.BoolValue = True
        cmpType.BoolValueSpecified = True
        cmpType.StringValue = "It works" 
        Dim retCmpType As localhost.CompositeType = client.GetDataUsingDataContract(cmpType) 
    That's It, you will see the output in console window. Press any key to exit the console application.
    Please note that I'm using web reference because I am not able to correcly implement WCF Client  for the service yet. In upcoming post, I will cover how to secure WCF service with basicHTTPBinding with wso2esb

    Tuesday, November 2, 2010

    Building Java Web Services with Axis2 and Eclipse

    I was working on middle-ware integration with wso2 and axis2 web services since last couple of months. In this post, I will show how to get started with axis2 development and deployment using Eclipse IDE.
    1. If you are not having an Eclipse IDE, I am using helios
    2. If you are already having Eclipse IDE. make sure you have WTP Plugin installed.
    3. Create a new workspace in eclipse
    4. Download and install any version of apache tomcat (I'm using tomcat 5.5). If you are having troubles configuring it on your machine, you can locate to apache tomcat help for installation here
    5. Add apache tomcat server to your Eclipse IDE, and here is how you can do it.
    6. Get Axis2
      Download latest source of Axis2 from here
    7. See Anil John's this article for properly configuring axis2 and related environment variables.
    8. Once you are done with step 7, you can start integrating axis2 with Eclipse IDE by using this article at eclipse WTP Tutorials.
    9. For deploying axis2 plugin using .aar package, donwload Apache Axis2 Archive plugin
    10. Extract the zip file of Apache Axis2 Archive plugin and copy the folder having plugin.xml and paste it to plugins folder of your eclipse installation root directory
    11. You are done with the configuration and ready to create a new web service. See this tutorial on eclipse WTP tutorials to create a new axis2 service.
    I am a .net developer, and successfully created and deployed the services created using Eclipse IDE to wso2 wsas.I have done this using windows xp, apache tomcat 5.5, axis2 1.5 and wso2 wsas 3.0.0. I hope this post will be helpful to you and will save your time to get started with axis2 development.
    I will try to share my experience of working with wso2 wsas and wso2 esb with you in upcoming posts.

    Monday, November 1, 2010

    Unable to engage module rampart

    If you have ever tried to create an axis web service with security, you probably have see this error:
    AxisFault: unable to engage module "rampart" 
    When I encountered this problem, I was working with eclipse having axis2 plug-ins. I found a solution in WSAS Forum.

    Wonderful thing to note is, I got this error fixed and while reading the forums of wso2 wsas, I got this link and I thought it would be good to share this.

    Note: This post is applicable to those who are not using axis2 repositories for development and using standalone eclipse projects. I was using the same.