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
- Host
- Contacts & Endpoints
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.