gpt4 book ai didi

c# - WCF - maxReceivedMessageSize

转载 作者:行者123 更新时间:2023-11-30 22:42:16 27 4
gpt4 key购买 nike

我在为较大的文件设置 maxReceivedMessageSize 时遇到问题。

我得到:

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.

这是我的服务器端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="HTTPBaseAddress" value="http://localhost:8080/WelcomeMessage/"/>
<add key="HTTPFileTransferAddress" value="http://localhost:8080/FileTransfer/"/>
</appSettings>
<system.web>
<compilation debug="false" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<services>
<service name="FS.Services.MessageService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint contract="FS.Interfaces.IMessageService" address="" binding="wsHttpBinding"/>
</service>
<service name="FS.Services.FileTransferService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint contract="FS.Interfaces.IFileTransferService" address="" binding="basicHttpBinding" bindingConfiguration="streamedHttpBinding"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="streamedHttpBinding"
messageEncoding="Text"
transferMode="Streamed"
maxReceivedMessageSize="400000000"/>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

这是我的客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="" binding="wsHttpBinding" contract="FS.Services.IMessageService"
name="FS.Services.MessageService" />
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="streamedHttpBinding"
contract="FS.Services.IFileTransferService" name="FS.Services.FileTransferService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="streamedHttpBinding" maxReceivedMessageSize="400000000"
messageEncoding="Text" transferMode="Streamed"/>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>

这是我连接客户端的方式:

BasicHttpBinding binding2 = new BasicHttpBinding("streamedHttpBinding");
EndpointAddress endpoint2 = new EndpointAddress("http://localhost:8080/FileTransfer");
ChannelFactory<IFileTransferService> channelFactory2 = new ChannelFactory<IFileTransferService>(binding2, endpoint2);
IFileTransferService proxy2 = channelFactory2.CreateChannel();
((IClientChannel)proxy2).Open();

此外,我还想使用流消息传输最大 500mb 的任何类型的文件。有人可以向我提供支持该功能的配置(或解决方案)吗?

谢谢!

最佳答案

您的客户端配置没有任何<client>将引用服务器的标记,并且您可以将绑定(bind)配置应用到增加的消息大小......

在您的服务器端,您需要定义服务及其端点:

<services>
<service name="YourNamespace.YourServiceClass">
<endpoint name="endpoint1"
address="http://server:8888/YourService.svc"
binding="basicHttpBinding"
bindingConfiguration="lageMessageTransfer"
contract="IYourServiceContract" />
</service>
</services>

在您的客户端端,您需要定义连接到服务端点之一的客户端端点

<client>
<endpoint name="Default"
address="http://server:8888/YourService.svc"
binding="basicHttpBinding"
bindingConfiguration="lageMessageTransfer"
contract="IYourServiceContract" />
</client>

更新:好的,现在我看到您的配置正常 - 但是您的客户端端点连接到哪里?你没有任何 address=定义!

 <client>
<endpoint name="FS.Services.FileTransferService"
address=""
binding="basicHttpBinding"
bindingConfiguration="streamedHttpBinding"
contract="FS.Services.IFileTransferService" />
</client>

关于c# - WCF - maxReceivedMessageSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4497928/

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