如何设置 .NET 客户端 Web 服务 ClientRuntime.MaxFaultSize

发布于 2024-09-27 03:20:54 字数 454 浏览 1 评论 0原文

我正在调用一个 java web 服务,该服务返回包含错误列表的FaultException 类型。所以响应消息的大小总是很大。

在我的 C# (clr3.5) 客户端中,我收到以下错误

“已超出传入消息的最大消息大小配额 (65536)。要增加配额,请在相应的绑定元素上使用 MaxReceivedMessageSize 属性。”

我相信解决此问题的方法是设置 ClientRuntime.MaxFaultSize msdn-doc

有没有办法在 app.config 中执行此操作?

I'm calling a java webservice that returns a type of FaultException that contains a list of errors. So the response message size is always large.

In my c# (clr3.5) client I get the following error

"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."

I believe the fix for this is to set the ClientRuntime.MaxFaultSize msdn-doc

Is there a way to do this in the app.config ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

静待花开 2024-10-04 03:20:54

您必须设置 ClientRuntime.MaxFaultSize 属性,请参阅此处< /a>

  1. 创建您的 MaxFaultSizeBehaviour

public class MaxFaultSizeBehavior : IEndpointBehavior
{
 private int _size;

 public MaxFaultSizeBehavior(int size)
 {
  _size = size;
 }

 public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
 {
 }

 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
  clientRuntime.MaxFaultSize = _size;
 }

 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
 }

 public void Validate(ServiceEndpoint endpoint)
 {
 }
}
  1. 将按客户端大小创建的行为:

a) 应用于 ChannelFactory:


ChannelFactory channelFactory = new ChannelFactory(binding, endPointAddress);
channelFactory.Endpoint.Behaviors.Add(new MaxFaultSizeBehavior(500000));

b) 或生成的代理:


proxy.Endpoint.Behaviors.Add(new SetMaxFaultSizeBehavior(500000));

You must set ClientRuntime.MaxFaultSize property, see here

  1. Create your MaxFaultSizeBehaviour

public class MaxFaultSizeBehavior : IEndpointBehavior
{
 private int _size;

 public MaxFaultSizeBehavior(int size)
 {
  _size = size;
 }

 public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
 {
 }

 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
  clientRuntime.MaxFaultSize = _size;
 }

 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
 }

 public void Validate(ServiceEndpoint endpoint)
 {
 }
}
  1. Apply created behaviour at client size:

a) to ChannelFactory:


ChannelFactory channelFactory = new ChannelFactory(binding, endPointAddress);
channelFactory.Endpoint.Behaviors.Add(new MaxFaultSizeBehavior(500000));

b) or to generated proxy:


proxy.Endpoint.Behaviors.Add(new SetMaxFaultSizeBehavior(500000));
萌逼全场 2024-10-04 03:20:54

当我们遇到这个问题时,我们按照错误消息更改了 app.config 的绑定配置中的 MaxReceivedMessageSize 属性。这不适合你吗?

   maxReceivedMessageSize="65536"  <!-- Change this -->

      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">

编辑:如果仍然不起作用,我发现 这篇文章。它建议创建合同行为属性。虽然示例将限制编码到属性构造函数中,但您可以从自己的配置值中提取。还没有看到直接的 .NET 配置,但我会查看行为配置。

When we ran into this problem, we followed the error message and changed the MaxReceivedMessageSize property in the bindings configuration of our app.config. Is this not working for you?

   maxReceivedMessageSize="65536"  <!-- Change this -->

      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">

EDIT: If that still doesn't work, I found this post. It suggests creating a Contract Behavior attribute. While the example codes the limit into the attribute constructor, you could pull from your own configuration value. Haven't seen a straight .NET configuration yet, but I'd look in behavior configuration.

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