我启用了wcf basicHttpBinding,并将TransferMode设置为“Streaming”。
问题是每次我从客户端的流中执行读操作时,我都读取了1536字节,这是一个以太网帧。
如何让我的wcf服务一次发送更大的数据包?
修改
所以,显然默认的BytesPerRead是4096,但是我在客户端和服务器上都改变了这个值。这是配置文件
此外,我发现了一个处理同一问题的未答复的帖子 WCF maxBytesPerRead limit to 4096
服务器 服务器
(请注意,我有两个端点,一个用于下载basicHttpBinding中的内容,一个用于使用ws2007HttpBinding进行通信,我指的是我的问题中的basicHttpBinding端点)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyBasicHttpBinding" allowCookies="true" maxBufferSize="955366"
maxBufferPoolSize="964285" maxReceivedMessageSize="955556" messageEncoding="Mtom"
transferMode="Streamed">
<readerQuotas maxDepth="60" maxStringContentLength="955556" maxArrayLength="955556"
maxBytesPerRead="955556" maxNameTableCharCount="955556" />
</binding>
</basicHttpBinding>
<ws2007HttpBinding>
<binding name="MyBinding" allowCookies="false">
<security mode="None" />
</binding>
</ws2007HttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ContentManagementServiceBehavior"
name="App_Code.Services.ContentManagement.ContentManagementService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"
listenUriMode="Explicit" />
<endpoint binding="ws2007HttpBinding" bindingConfiguration="MyBinding"
name="ws2007Endpoint" contract="App_Code.Services.ContentManagement.IContentManagementService"
listenUriMode="Explicit" />
<endpoint address="/download" binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
name="basicHttpBinding" contract="App_Code.Services.ContentManagement.IContentManagementDownlodService" />
<host>
<baseAddresses>
<add baseAddress="/Services/ContentManagement/ContentManagementService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ContentManagementServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
客户端
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="92429000" maxReceivedMessageSize="65536000" messageEncoding="Mtom"
textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
<readerQuotas maxDepth="90" maxStringContentLength="65536000" maxArrayLength="65536000"
maxBytesPerRead="655360" maxNameTableCharCount="65536000" />
<security mode="None" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="ws2007Endpoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288646" maxReceivedMessageSize="65536646"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="819264564"
maxArrayLength="163846764" maxBytesPerRead="40964543" maxNameTableCharCount="16384564" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport realm="" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="<absolute address>"
binding="wsHttpBinding" bindingConfiguration="ws2007Endpoint"
contract="ContentManagementServiceReference.IContentManagementService"
name="ws2007Endpoint" />
<endpoint address="<absolute address>"
binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"
contract="ContentManagementServiceReference.IContentManagementDownlodService"
name="basicHttpBinding" />
</client>
</system.serviceModel>
答案 0 :(得分:0)
看一下这个主题:http://social.msdn.microsoft.com/forums/en-US/wcf/thread/e1f7b040-39a8-4ca8-9def-96b2b47c0d6f/
我认为有几种选择非常适合您的问题。
谢谢,
罗伯特。
答案 1 :(得分:0)
您可以尝试更改maxBytesPerRead
属性:
<bindings>
<basicHttpBinding>
<binding name="Streamed" TransferMode="Streamed" TextEncoding="Mtom"
maxMessageReceivedSize="4000000">
<readerQuotas mexBytesPerRead="8192" />
</binding>
</basicHttpBinding>
</bindings>