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:
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).