How to use WCF services without svcutil.exe?

I found two ways to use the WCF service without help svcutil.exe:

  • ClientBase<IService>
  • ChannelFactory<IService>

I know that ClientBaseprobably uses ChannelFactory. But I'm talking about choosing between writing:

public sealed class ServiceClient 
    : ClientBase<IService>, IService
{
    ReturnType IService.MethodName(ParameterType parameterName)
    {
        return Channel.MethodName(parameterName);
    }
}

// later
IService client = new ServiceClient();
var result = client.MethodName(parameterName);

or

ChannelFactory<IMyService> channelFactory = new ChannelFactory<IMyService>();
channelFactory.Open();

var channel = channelFactory.CreateChannel(); 
var result = channel .MethodName(parameterName);

channelFactory.Close();

Which one to choose?

+3
source share
1 answer

What are your selection criteria?

Functionally, after all, both approaches work very well and basically give you the same result.

What do you want to base your decision on?

My advice: choose a style with which you will be comfortable! Approach c ChannelFactory<IService>probably requires you to write less and less worldly code, so perhaps this will be a small advantage for this approach.

, .NET , - , , , .

+5

Source: https://habr.com/ru/post/1783899/


All Articles