Create Dynamic Proxies objects

混江龙づ霸主 提交于 2019-12-11 02:05:48

问题


Is there a way to create WCF proxy objects on the fly without using codedom? By on the fly I mean during runtime. So lets say I have a smart client application that is accessing a WCF service. The Data Contract for the WCF service is changed while the client is running. I want to dynamically create a new proxy object that reflects the changed data contract.


回答1:


You should read this article: WCF the Manual Way… the Right Way

And look into using the ChannelFactory class. You are going to have alot of reflection to create and invoke the members if the contract changes on the fly but I can't think of any reason you shouldn't be able to do it.




回答2:


I came up with a solution, using a shared assembly for contracts and endpoint interfaces.

So The Projects Would Be

  1. Host
  2. Contacts & Endpoints
  3. Client With Proxy

    public class YourProxy : ClientBase {}




回答3:


Be careful about doing too much stuff on the fly. Even using reflection it might become too easy to couple your Client/Proxy/Service/Contract together too much.

Creating manual proxies and adding them as a reference to your client is a fantastic idea.



来源:https://stackoverflow.com/questions/476827/create-dynamic-proxies-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!