WCF 从 web.config 文件读取端点行为
我有一个 WCF 服务,它连接到多个客户端。
我想要做的是动态创建 WCF 服务使用的客户端。
通过继承 ServiceFactory
类创建客户端就完成了,而且非常简单。我正在努力解决的是如何从 web.config
文件中读取端点行为并将它们添加到客户端?
代码文件
BasicHttpBinding binding = new BasicHttpBinding(bindingConfigName);
EndpointAddress endpoint = new EndpointAddress(endpointUrl);
ChannelFactory<IShoppingSoap> clientEndpoint = new ChannelFactory<IShoppingSoap>(binding, endpoint);
base.Endpoint.Behaviors.Add(*Get the behavior from the config file*);
return base.CreateChannel();
Web.config
文件:
<behaviors>
<endpointBehaviors>
<behavior name="EndpointBehaviour_GmCustom">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
<behavior>
</endpointBehaviors>
</behaviors>
I've have a WCF service which has multiple clients that it connects to.
What I want to do is to create the clients dynamically the WCF services consumes.
Creating the clients by inheriting from the ServiceFactory<TChannel>
class is done and very simple. What I'm struggling with is how to read Endpoint behaviours from the web.config
file and add them to the clients?
Code file
BasicHttpBinding binding = new BasicHttpBinding(bindingConfigName);
EndpointAddress endpoint = new EndpointAddress(endpointUrl);
ChannelFactory<IShoppingSoap> clientEndpoint = new ChannelFactory<IShoppingSoap>(binding, endpoint);
base.Endpoint.Behaviors.Add(*Get the behavior from the config file*);
return base.CreateChannel();
Web.config
file :
<behaviors>
<endpointBehaviors>
<behavior name="EndpointBehaviour_GmCustom">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
<behavior>
</endpointBehaviors>
</behaviors>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到解决方案..我认为..您必须完成端点中的每个操作并更改那里的 maxItemsInObjectGraph 。
在这里找到解决方案
http:// www.lapathy.com/home/2009/9/30/programmatically-setting-maxitemsinobjectgraph-in-wcf.html
Found the solution.. i think.. you have to go through each of the operations in the endpoint and change the maxItemsInObjectGraph there.
Found the solution here
http://www.lapathy.com/home/2009/9/30/programmatically-setting-maxitemsinobjectgraph-in-wcf.html