Any WCF Client Proxy Generator for channels manage

2019-08-23 12:22发布

Which best ChannelFactrory wrapper would you recommand? I`m searching for a simple one that will handle the channel creation process and reopen in when needed.

1条回答
狗以群分
2楼-- · 2019-08-23 13:06

The channel creation process is already very simple with ChannelFactory.

I guess if you pre-generate a service proxy using svcutil that would generate a wrapper for you. But I don't think the wrapper would be any simpler to use.

// Create service proxy on the fly
var factory = new ChannelFactory<IMyServiceContract>("NameOfMyClientEndpointInConfigFile");
var proxy = factory.CreateChannel();

// Create data contract
var requestDataContract = new MyRequestType();

// Call service operation.
MyResponseType responseDataContract = proxy.MyServiceOperation(requestDataContract);

In the above example, IMyServiceContract is your service contract, and MyRequestType and MyResponseType are your data contracts, which you can use by referencing the assembly which the service also references (which defines these types).

查看更多
登录 后发表回答