DCSIMG
Coupling Issue Solution by WCF Technology - Part II - Vladislav Amirov

Vladislav Amirov

Integrating .NET technologies in to the enterprise system is an exciting proposition!
www.easy-forex.com

Coupling Issue Solution by WCF Technology - Part II

In my first post we could see different client and service contract interfaces that successfully worked in reviewed example. The differences between two interfaces were in following details:
  1. Namespace:  CustomBaseServer and CustomBaseClient – works without specify solution
  2. Interface Name: Trading and Trading1 – solved by [ServiceContract (Name=...)]
  3. Method Name:  GetRate and GetRate1 - solved by [OperationContract(Name=...)]
So we have enough reasons to say that interfaces really diverse. But between two contacts can be additional differences worked and supported by WCF as well:
  1. Number of methods
  2. Number of method parameters
  3. Name of method parameters
Example Source Code

File: ITrading.cs - Service Interface Code Snippet

namespace CustomBaseServer
{

    [ServiceContract]

    interface ITrading

    {

        [OperationContract]

        void Foo1();

 

        [OperationContract]

        void Foo2(string text);

 

        [OperationContract]

        void Foo3(

            //[MessageParameter(Name = "p1")] int x

            //,[MessageParameter(Name = "p2")] int y

            //,[MessageParameter(Name = "p3")] int z

            int x, int y, int z);

 

        [OperationContract]

        void Foo4(double val);

 

        void Foo88(DateTime dt);

    }

}

 

 

File: ITrading.cs - Client Interface Code Snippet 

namespace CustomBaseClient

{

    [ServiceContract(Name = "ITrading")]

    interface ITrading1

    {

        [OperationContract]

        void Foo();

 

        [OperationContract]

        void Foo1();

 

        [OperationContract]

        void Foo2();

 

        [OperationContract]

        void Foo3(int y, int var2);

 

        void Foo99();

    }

}

 

 

File: Programm.cs - Client Consol Code Snippet 

namespace CustomBaseClient

{

    class Program

    {

        //Run it in debug mode

        static void Main(string[] args)

        {

            Console.WriteLine("Client start...");

            var channelFactory = new ChannelFactory<ITrading1>("ITradingBasicHttp");

            //var channelFactory = new ChannelFactory<ITrading1>("ITradingWebService");

            var trading = channelFactory.CreateChannel();

 

            //ActionNotSupportedException, this method undefined in service contract

            trading.Foo();

 

            //Ok

            trading.Foo1();

 

            //Ok, but the service side gets null string

            trading.Foo2();

 

            //Ok, but service side gets only "y" parameter, x and z is initialized with

            //zero value. Even first client and second service parameter matched by

            //common ("y") name. It's work, great!  

            trading.Foo3(11 /*y*/, 22 /*var*/);

 

            //System.NotSupportedException, this method is not marked with

            //OperationContractAttribute in both client and service sides.

            trading.Foo99();

 

            Console.ReadLine();

        }

    }

}

 

Example Source Code

So, WCF is able to match in runtime service contract methods and its parameters numbers and names. It's a very useful capability for enterprise flexibility and amazing SOAP using structure for service versioning management (Service Versioning in my next post).

 

פורסם: Jul 14 2009, 02:02 AM by FanMix | with no comments
תגים:,
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 7 and 1 and type the answer here:


Enter the numbers above: