如何在没有 svcutil 的情况下创建客户端代理或在 wcf 中添加服务引用? [英] How to create client proxy without svcutil or add service reference in wcf?
本文介绍了如何在没有 svcutil 的情况下创建客户端代理或在 wcf 中添加服务引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在没有 svcutil.exe 的情况下创建客户端代理或在 wcf 中添加服务引用?我想在编译时创建一个客户端代理.
How can I create a client proxy without svcutil.exe or add service reference in wcf? I want to create a client proxy at compile time.
推荐答案
如果您可以访问单独 DLL 中的服务契约(IService 接口),您可以添加对该服务契约 DLL 的引用,然后执行类似的操作:
If you have access to the service contract (the IService interface) in a separate DLL, you can add a reference to that service contract DLL and then do something like:
NetTcpBinding binding = new NetTcpBinding();
EndpointAddress address = new EndpointAddress("net.tcp://localhost:9000/YourService")
ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, address);
IService proxy = factory.CreateChannel();
然后您就拥有了以编程方式创建的代理,您现在可以随意使用它.
and then you have your programmatically created proxy, which you can now use as you wish.
这篇关于如何在没有 svcutil 的情况下创建客户端代理或在 wcf 中添加服务引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文