gpt4 book ai didi

c# - 如何设置 .NET 客户端 web 服务 ClientRuntime.MaxFaultSize

转载 作者:太空狗 更新时间:2023-10-30 00:57:59 25 4
gpt4 key购买 nike

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

在我的 c# (clr3.5) 客户端中,出现以下错误

“已超过传入消息的最大消息大小配额 (65536)。要增加配额,请在适当的绑定(bind)元素上使用 MaxReceivedMessageSize 属性。”/p>

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

有没有办法在 app.config 中做到这一点?

最佳答案

您必须设置 ClientRuntime.MaxFaultSize 属性,see here

  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));

关于c# - 如何设置 .NET 客户端 web 服务 ClientRuntime.MaxFaultSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3916483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com