Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » WCF » Interoperability between WCF and Oracle Application Server

Interoperability between WCF and Oracle Application Server

This article is to illustrate techniques and architecture that address the situation of one service running in WCF and a client consuming this service.

Author Rank :
Page Views : 4161
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Summary

This article is part of series intended to show how to use Web Services related technologies to interoperate applications running in different platforms, in this case, the most common scenario between Microsoft.NET and Oracle AS platforms. This article is to illustrate techniques and architecture that address the situation of one service running in WCF and a client consuming this service.

Creating a Web Service in Windows Communication Foundation.

This section describes how to create a Web Service using the Windows Communication Foundation, the new Microsoft platform for developing connected applications. Our target Web Service, like in the first article, will expose the functionality of Financial System.

The section contains the following topics:

  1. Installing Windows Communication Foundation.
  2. Defining the interface of the service and creating the Web Service.
  3. Deployment and running of the Web Service.

Installing Windows Communication Foundation.

You need to download from Microsoft Portal (
http://www.microsoft.com) the runtime environment (dotnetfx3.exe), the SDK (6.0.6000.0.0.WindowsSDK_Vista_rtm.DVD.Rel.DVD.Rel.img), and the Visual Studio extension for WCF (vsextwfx.msi). And finally, install this requirements in the this same order.

To create the Web Service in WCF, you have to start Visual Studio.NET and then select File|New|Project in the main menu. In the New Project windows at the Project Types tree go to Visual C#|NET Framework 3.0 and choose WCF Service Library from the Visual Studio installed templates area and enter a project name such as FinancialServiceLib, and a directory where to store the project's file. Under the hood Visual Studio.NET uses the extension for WCF to create the WCF components such as the configuration information, the interface of the service, the WCF service, the reference to WCF platforms objects, and the service host components for the case of using Windows or Console applications to host the service and it's remarkable to say that in other runtime environments such as Web Applications or Windows Services it is not necessary these components.

Defining the interface of the service and creating the Web Service.

To define the service's interface component, you must create the file IFinancialService.cs as illustrated in Listing 1.

using System;

using System.Collections.Generic;

using System.Text;

using System.ServiceModel;

using System.Runtime.Serialization;

 

namespace FinancialServiceLib

{

    [ServiceContract()]

    public interface IFinancialService

    {

        [OperationContract]

        int Debit(int nAccount, int nAmount);

    }
}


Listing 1.

To create the Web Service component, you must define a class which implements the former interface in a file FinancialServiceLib.cs as illustrated in Listing 2.

using System;

using System.Collections.Generic;

using System.Text;

using System.ServiceModel;

using System.Runtime.Serialization;

 

namespace FinancialServiceLib

{

    public class FinancialService : IFinancialService

    {

        public int Debit(int nAccount, int nAmount)

        {

            //Here comes the business logic.

            return nAmount;

        }

    }
}


Listing 2.


The service host component is defined as illustrated in Listing 3.

using System;

using System.Collections.Generic;

using System.Text;

using System.ServiceModel;

using System.Runtime.Serialization;

 

namespace FinancialServiceLib

{

    public class FinancialServiceHost

    {

        public static ServiceHost objFinancialServiceHost = null;

        public static void StartService()

        {

            //Consider putting the baseAddress in the configuration system

            //and getting it here with AppSettings

            Uri baseAddress = new Uri("http://localhost:8080/FinancialService.svc");

 

            //Instantiate new ServiceHost

            objFinancialServiceHost = new ServiceHost(typeof(FinancialServiceLib.FinancialService), baseAddress);

 

            //Open myServiceHost

            objFinancialServiceHost.Open();

        }

        public static void StopService()

        {

            //Call StopService from your shutdown logic (i.e. dispose method)

            if (objFinancialServiceHost.State != CommunicationState.Closed)

                objFinancialServiceHost.Close();

        }

    }

}

Listing 3.

And finally, you create the configuration file with all the runtime information needed by the service host component for its initialization. You may define the address to access the service, the endpoints or interface and its underlying communication mechanism for this example, I use the binding wsHttpBinding, well as other information to bind successfully to the service such as security, policies, etc. For example, in this case, we allows the client to discover metadata of the service using the http protocol and the Get method, that is, you can use a browser to access the service definition structured according to the rules of WSDL and save this file in your computer directory (text highlighted in yellow).See Listing 4.

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.serviceModel>

    <services>

      <service name="FinancialServiceLib.FinancialService" behaviorConfiguration="FinancialServiceLib.FinancialServiceBeh">

        <endpoint contract=" FinancialServiceLib.IFinancialService" binding="wsHttpBinding" />

      </service>

    </services>

    <behaviors>

      <serviceBehaviors>

        <behavior name="FinancialServiceLib.FinancialServiceBeh">

          <serviceMetadata httpGetEnabled="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

</configuration>

Listing 4.


Deployment and running of the Web Service.

To deploy and run the WCF service, we're going to create a Console application. Go to File|New|Project and choose Console Application template. Then add a reference to the library create in the last step by right-clicking on the console project, and select Add Reference and from the Add Reference windows at the Projects tab choose the FinancialServiceLib.

The business logic for this application is straightforward as illustrated in the following listing.

using System;

using System.Collections.Generic;

using System.Text;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            FinancialServiceLib.FinancialServiceHost.StartService();

 

            System.Console.WriteLine("Please, enter any key to finish ...");

            System.Console.ReadLine();

        }

    }

}

Listing 5.

Consuming the WCF Web Service.

This section describes how to consume the Web Service using Windows Communication Foundation.

The section contains the following topics:

  1. Creating the proxy.
  2. Running the application.

Creating the proxy.

You need to launch the JDeveloper IDE, and create an application and one project. Select File|New from the main menu. Enter a name for the application name, and a place to store the application components in Directory Name, and finally set a descriptive name for the project such as FinancialWCFService_Client.

To create the proxy, go to File|New and navigate the Categories tree to the Business Tier| Web Services and choose Web Service Proxy. Finally, you must follow the instruction of the wizard, setting the address where the WSDL reside, for example
http://localhost:8080/FinancialService.svc?wsdl, the package name and so on. Afterwards, you have generated a proxy to the WCF service as illustrated in the Listing 6.

// This source file is generated by Oracle tools and is subject to change

// It is a utility client for invoking the operations of the Web service port.

// For reporting problems, use the following

// Version = Oracle WebServices (10.1.3.1.0, build 061008.0900.00025)

package com.olam.jdbcexample.proxy;

import oracle.webservices.transport.ClientTransport;

import oracle.webservices.OracleStub;

import javax.xml.rpc.ServiceFactory;

import javax.xml.rpc.Stub;

public class WSHttpBinding_IFinancialServiceClient

{

    private com.olam.jdbcexample.proxy.IFinancialService _port;

    public WSHttpBinding_IFinancialServiceClient() throws Exception

    {

        ServiceFactory factory = ServiceFactory.newInstance();

        _port = ((com.olam.jdbcexample.proxy.FinancialService)factory.loadService

        (com.olam.jdbcexample.proxy.FinancialService.class)).getWSHttpBinding_IFinancialService();

    }

   

    /**

     * @param args

     */

    public static void main(String[] args)

    {

        try

        {

            com.olam.jdbcexample.proxy.WSHttpBinding_IFinancialServiceClient myPort = new

            com.olam.jdbcexample.proxy.WSHttpBinding_IFinancialServiceClient();

            System.out.println("calling " + myPort.getEndpoint());      

            int nResult = myPort.debit(3,200);

            System.out.println("Debit the account id 3, the amount 200 and result is "+nResult);

        }

        catch (Exception ex)

        {

            ex.printStackTrace();

        }

    }   

   
   
/**

     * delegate all operations to the underlying implementation class.

     */

    
    
public Integer debit(Integer nAccount, Integer nAmount) throws java.rmi.RemoteException

    {

        return _port.debit(nAccount, nAmount);

    }

   
   
/**

     * used to access the JAX-RPC level APIs

     * returns the interface of the port instance

    */

    public com.olam.jdbcexample.proxy.IFinancialService getPort()

    {

        return _port;

    }

    public String getEndpoint()
    {

        return (String) ((Stub) _port)._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY);

    }

    public void setEndpoint(String endpoint)
    {

        ((Stub) _port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, endpoint);

    }

    public String getPassword()
    {

        return (String) ((Stub) _port)._getProperty(Stub.PASSWORD_PROPERTY);

    }

    public void setPassword(String password)
    {

        ((Stub) _port)._setProperty(Stub.PASSWORD_PROPERTY, password);

    }

    public String getUsername()
    {

        return (String) ((Stub) _port)._getProperty(Stub.USERNAME_PROPERTY);

    }

    public void setUsername(String username)
    {

        ((Stub) _port)._setProperty(Stub.USERNAME_PROPERTY, username);

    }

    public void setMaintainSession(boolean maintainSession)
    {

        ((Stub) _port)._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.valueOf(maintainSession));

    }
   

    public boolean getMaintainSession()
    {

        return ((Boolean) ((Stub) _port)._getProperty(Stub.SESSION_MAINTAIN_PROPERTY)).booleanValue();

    }

    /**

     * returns the transport context

     */

   
   
public ClientTransport getClientTransport()
    {

        return ((OracleStub) _port).getClientTransport();

    }

}

Listing 6.

As you can see, the generated proxy has main operation (highlighted in yellow) to test the proxy. Then you must go to the Application Navigator and run this executable Java component.

Conclusions

This article explained the techniques used to implement the Web Service interoperability scenario between WCF and Oracle Application Server. Specifically, it covered how to invoke a WCF's Web Service from an Oracle platform's client.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
John Charles Olamendy
He’s a senior Integration Solutions Architect and Consultant. His primary area of involvement is in Object-Oriented Analysis and Design, Database design , Enterprise Application Integration, Unified Modeling Language, Design Patterns and Software Development Process. He has knowledge and extensive experience in the development of Enterprise Applications using Microsoft.NET and J2EE technologies and standards. He is proficient with distributed systems programming; and business-process integration and messaging using the principles of the Services Oriented Architecture (SOA) and related technologies such as Microsoft BizTalk Server, Web Services (Windows Communication Foundation, WSE, BEA WebLogic, Oracle AS and Axis) through multiple implementations of loosely-coupled system. He’s a prolific blogger contributing to .NET and J2EE communities and actively writes articles on subjects relating to integration of applications, business intelligence, and enterprise applications development. He holds a Master’s degree in Business Informatics at Otto Von Guericke University, Magdeburg, Germany. He was recently awarded as MVP. He currently works in the telecommunication industry and delivers integration solutions for this industry. He harbors a true passion for the technology.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Interoperate Application by I got your IP On December 7, 2010

Good work.

Reply | Email | Modify 
Discover the top 5 tips for understanding .NET Interop
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.