user3883423
user3883423

Reputation: 247

Can any one provide me some idea about creating generic framework for wcf client by using factory patterns?

In my work environment I came across a requirement to create framework for client proxy using factory patterns ,so that actual clients instead of adding service reference to service they use this framework. As I don't have much knowledge can anyone provide some idea or useful links for the same.

How about using "ChannelFactory" in framework? or framework should have service reference?(My framework should make use of channelfactory/proxy)

thank you..

Upvotes: 0

Views: 25

Answers (1)

Abhinav Galodha
Abhinav Galodha

Reputation: 9928

I believe you are looking for ChannelFactory<TChannel>.CreateChannel method. This allows for Creating a channel of a specified type to a specified endpoint address.

This is one of the ways to create a proxy for WCF Services. A very basic example is as shown below

using System;
using System.ServiceModel;


[ServiceContract()]
interface IService
{
    [OperationContract()]
     string GetData(string inputString);
}

public class ConcreteService : IService
{
    public string GetData(String inputString) 
    {
        return "you enetered :" + inputString;
    }
}

public class Test
{
    static void Main()
    {
        // Create a channel factory.
        BasicHttpBinding myBinding = new BasicHttpBinding();

        EndpointAddress myEndpoint = new EndpointAddress("http://localhost/ConcreteService/Ep1");

        ChannelFactory<IMath> myChannelFactory = new ChannelFactory<IService>(myBinding, myEndpoint);

        // Create a channel.
        IService wcfClient1 = myChannelFactory.CreateChannel();
        string output = wcfClient1.GetData("abc");
        ((IClientChannel)wcfClient1).Close();

      }

}

You can read more about this here.

Upvotes: 2

Related Questions