Create Dynamic Proxies objects

2019-07-22 20:51发布

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.

3条回答
我只想做你的唯一
2楼-- · 2019-07-22 21:05

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.

查看更多
Summer. ? 凉城
3楼-- · 2019-07-22 21:06

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 {}

查看更多
Ridiculous、
4楼-- · 2019-07-22 21:26

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.

查看更多
登录 后发表回答