Thursday, November 4, 2010

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>
          <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)
      Console.WriteLine(strData)
      
      Dim cmpType As New localhost.CompositeType
      cmpType.BoolValue = True
      cmpType.BoolValueSpecified = True
      cmpType.StringValue = "It works" 
      Dim retCmpType As localhost.CompositeType = client.GetDataUsingDataContract(cmpType) 
      Console.WriteLine(retCmpType.StringValue)
      Console.ReadKey()
      
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

2 comments:

  1. Hi. A try this with the ESB v4.5.0 and I have this problem:

    message send by ESB

    POST /service/service1.svc HTTP/1.1
    Content-Type: application/soap+xml; charset=UTF-8; action="http://tempuri.org/IService1/GetData"
    Cookie: menuPanel=visible; menuPanelType=main; region3_registry_menu=visible; region1_manage_menu=visible; region5_my_identity_menu=visible; region1_dashboard_main_menu=visible; wso2.carbon.rememberme=admin-d4356f82-e26a-4932-9e78-1a90199097da; JSESSIONID=D3FD34FC6238E1EAC9538311ACE1A2E3; Modernizr=; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; MSG13492919241270.6344102672428753=true; requestedURI="../../carbon/service-mgt/service_info.jsp?serviceName=testNET"; MSG13492936069900.5787983074513814=true
    Transfer-Encoding: chunked
    Host: 10.55.18.111:8888
    Connection: Keep-Alive
    User-Agent: Synapse-HttpComponents-NIO

    102
    56
    0

    message recieve:

    HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml; charset=UTF-8; action="http://tempuri.org/IService1/GetData"' was not the expected type 'text/xml; charset=utf-8'.
    Server: Microsoft-IIS/7.5
    X-Powered-By: ASP.NET
    Date: Tue, 04 Dec 2012 23:53:54 GMT
    Content-Length: 0


    any idea why this happen?

    ReplyDelete
    Replies
    1. You can try by disabling chunking to getover the above problem. Refer http://sanjeewamalalgoda.blogspot.com/2012/08/how-to-disable-chunking-wso2-esb-proxy.html for more info.

      - Asanka

      Delete

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