我在为较大文件设置 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 - 最大接收消息大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4497928/