【发布时间】:2011-10-04 08:27:11
【问题描述】:
我有一个场景,我必须使用 WCF 服务上传一些数据,如果上传的内容大小小于 1MB,我能够成功完成,但如果上传的内容大小大于 1MB,我会收到类似的错误这个
错误信息:-
接收到的 HTTP 响应时出错 “http://localhost/abc/Admin/Services/Package”。这可能是 由于服务端点绑定不使用 HTTP 协议。这 也可能是由于 HTTP 请求上下文被 服务器(可能是由于服务关闭)。查看服务器日志 了解更多详情。
我认为这是关于我在 app.config 中的绑定中的缓冲区大小设置的错误。
我的 app.config 文件客户端设置如下所示。
<system.serviceModel>
<client>
<endpoint address="http://localhost/abc/Services/Package"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_PackageService"
contract="PackageService.PackageService" name="BasicHttpBinding_PackageService" />
</client>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="ServiceContracts.SearchServiceContract"
behaviorConfiguration="SearchServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/xyz/SearchService"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8080/xyz/SearchService -->
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="NoSecurityBinding"
contract="ServiceContracts.ISearchServiceContract" />
<!-- the mex endpoint is exposed at http://localhost:8080/xyz/SearchService/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<service name="ServiceContracts.PackageServiceContract"
behaviorConfiguration="PackageServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/xyz/PackageService"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8080/xyz/PackageService -->
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="NoSecurityBinding"
contract="ServiceContracts.IPackageServiceContract" />
<!-- the mex endpoint is exposed at http://localhost:8080/xyz/PackageService/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SearchServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
<behavior name="PackageServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_PackageService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="268435456" maxBufferPoolSize="268435456" maxReceivedMessageSize="268435456"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="268435456" maxNameTableCharCount="268435456" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="NoSecurityBinding">
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
请问有人知道解决方法吗?我的上传大小可以达到 2GB。那么我必须给出的确切缓冲区大小或 maxReceivedMessageSize 或 maxStringContentLength 是多少?
【问题讨论】:
标签: wcf wcf-binding wcf-security wcf-data-services wcf-client