且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

任何用于频道管理的 WCF 客户端代理生成器?

更新时间:2023-09-18 19:05:16

ChannelFactory 的频道创建过程已经非常简单.

The channel creation process is already very simple with ChannelFactory.

我想如果您使用 svcutil 预先生成一个服务代理,它会为您生成一个包装器.但我不认为包装器使用起来会更简单.

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);

在上面的示例中,IMyServiceContract 是您的服务契约,而 MyRequestType 和 MyResponseType 是您的数据契约,您可以通过引用服务也引用的程序集(定义这些类型)来使用它们.

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