WCF 从 web.config 文件读取端点行为

发布于 2024-09-24 00:15:30 字数 910 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2024-10-01 00:15:30

找到解决方案..我认为..您必须完成端点中的每个操作并更改那里的 maxItemsInObjectGraph 。

foreach (OperationDescription operation in base.Endpoint.Contract.Operations)    
{    
operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = 2147483646;                    
}

在这里找到解决方案

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.

foreach (OperationDescription operation in base.Endpoint.Contract.Operations)    
{    
operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = 2147483646;                    
}

Found the solution here

http://www.lapathy.com/home/2009/9/30/programmatically-setting-maxitemsinobjectgraph-in-wcf.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文