gpt4 book ai didi

azure - azure WCF中继中超过64K时出现异常

转载 作者:行者123 更新时间:2023-12-02 01:07:33 24 4
gpt4 key购买 nike

我有这个代码,我是从这个 azure wcf relay 实现的

当发送大于 64K 的消息时,我收到此异常(对于较小的消息,它可以正常工作):

System.ServiceModel.CommunicationException:“已超出远程 channel 的传入消息的最大消息大小配额。有关更多详细信息,请参阅服务器日志。

根据此 quota web page NetTcpRelayBinding 中的配额是无限的

这是我的代码

class WCFRelay
{
[ServiceContract(Namespace = "urn:ps")]
interface IProblemSolver
{
[OperationContract]
int Test(byte[] bytes);
}

class ProblemSolver : IProblemSolver
{
public int Test(byte[] bytes)
{
return bytes.Length;
}
}

interface IProblemSolverChannel : IProblemSolver, IClientChannel { }

public static void CreateClient()
{
var cf = new ChannelFactory<IProblemSolverChannel>(
new NetTcpRelayBinding(),
new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", "...", "solver")));

cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior
{ TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "...") });

using (var ch = cf.CreateChannel())
{
// if its 50K its ok - if its 70K i get exception
Console.WriteLine(ch.Test(new byte[1000 * 70]));
}
}

public static void CreateServer()
{
ServiceHost sh = new ServiceHost(typeof(ProblemSolver));

sh.AddServiceEndpoint(
typeof(IProblemSolver), new NetTcpRelayBinding(),
ServiceBusEnvironment.CreateServiceUri("sb", "...", "solver"))
.Behaviors.Add(new TransportClientEndpointBehavior
{
TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "...")
});

sh.Open();

while (true)
{
Thread.Sleep(1000);
}
Console.WriteLine("Press ENTER to close");
Console.ReadLine();

sh.Close();
}
}

最佳答案

根据您的描述,我检查了这个问题并找到了原因。构造 NetTcpRelayBinding 时,MaxBufferSizeMaxReceivedMessageSize 的默认值为 64K,如下所示:

enter image description here

在构造 NetTcpRelayBinding 实例时,您可以将 MaxBufferSizeMaxReceivedMessageSizeMaxBufferPoolSize 指定为更大的值在您的服务器和客户端。

结果:

enter image description here

关于azure - azure WCF中继中超过64K时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46925928/

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