WCF流媒体无法传输大文件
我正在制作用于传输文件的WCF服务。我对WCF只有基本的了解,并遵循了MSDN教程: 我开始使用字节数组来传输文件,但一旦文件变得有点大(100kb就足够了),它就会因请求错误而失败。 我遵循了另一个指南,改为使用消息流,它也适用于小文件,但在像旧版本这样的大文件中失败。我怀疑故障出在我的配置文件中,因为svcutil.exe生成的配置文件没有说明任何关于流的内容。 这是我的客户端app.config:WCF流媒体无法传输大文件,wcf,streaming,file-transfer,Wcf,Streaming,File Transfer,我正在制作用于传输文件的WCF服务。我对WCF只有基本的了解,并遵循了MSDN教程: 我开始使用字节数组来传输文件,但一旦文件变得有点大(100kb就足够了),它就会因请求错误而失败。 我遵循了另一个指南,改为使用消息流,它也适用于小文件,但在像旧版本这样的大文件中失败。我怀疑故障出在我的配置文件中,因为svcutil.exe生成的配置文件没有说明任何关于流的内容。 这是我的客户端app.config: <?xml version="1.0" encoding="utf-8"?> &
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDocPublisher" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="200000000" maxStringContentLength="200000000" maxArrayLength="200000000"
maxBytesPerRead="200000000" maxNameTableCharCount="200000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService/docPublisher"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDocPublisher"
contract="IDocPublisher" name="WSHttpBinding_IDocPublisher">
<identity>
<userPrincipalName value="Emil-PC\Emil" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
这是服务器app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"
httpHelpPageEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="serviceBehavior"
name="DocPublisher">
<endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService"
name="basicHttpStream"
binding="basicHttpBinding"
bindingConfiguration="httpLargeMessageStream"
contract="IDocPublisher" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="httpLargeMessageStream"
maxReceivedMessageSize="200000000"
maxBufferSize="200000000"
transferMode="Streamed"
messageEncoding="Mtom" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
尝试在客户端增加发送超时和读卡器配额,在服务器端设置缓冲区大小。结果表明,配置文件不是真正的问题,问题是服务器app.config从未被使用,因为msdn教程不使用app.config,而是在main方法中创建端点。我无法在服务器上设置缓冲区大小,只是最大缓冲大小。我尝试了你建议的改变,但没有成功。我已经用新的值更新了上面的代码。你能详细说明一下吗,埃米尔?如何更改动态创建的端点?