c# - WCF 从 web.config 文件中读取终结点行为

标签 c# wcf web-config

我有一个 WCF 服务,它连接到多个客户端。

我想做的是动态创建 WCF 服务使用的客户端。

通过继承 ServiceFactory<TChannel> 创建客户端类(class)已经完成,非常简单。我正在努力解决的问题是如何从 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>

最佳答案

找到解决方案..我认为..您必须完成端点中的每个操作并更改那里的 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

关于c# - WCF 从 web.config 文件中读取终结点行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3759635/

相关文章:

c# - 为数组中字符串的每个字母输出 _ (hangman)

ASP.NET 4.5 Web.config 错误

asp.net - ASP.NET web.config 中的 SSL 规则异常

.net - 加密 web.config 毫无意义吗?

c# - 自定义 web.config 部分 (ASP.NET)

c# - Entity Framework 中的 Sql Char(13) 和 isnull 的替代品是什么?

c# - 从 C# 加载 C++ Windows 运行时组件时出现异常

c# - 如何在调用 SmtpClient.Send() 之前知道域是错误的?

c# - 在 WCF 或 WebAPI 方法 (IIS) 中返回 "Task<int>"而不是 "int"的好处

c# - WebHttpBinding 绑定(bind)中使用的默认 header 内容类型值