C# WCF远程服务器返回意外响应:(413)请求实体太大
我是WCF新手,我正在编写一个WCF服务,该服务具有一个数据协定,该协定将字节数组作为属性。当我转换一个小文件时,它可以工作,但当我使用一个较大的图像时,比如说1兆或更大,我得到 远程服务器返回意外响应:(413)请求实体太大。 我需要帮助 这是我的服务器端web.configC# WCF远程服务器返回意外响应:(413)请求实体太大,c#,vb.net,wcf,C#,Vb.net,Wcf,我是WCF新手,我正在编写一个WCF服务,该服务具有一个数据协定,该协定将字节数组作为属性。当我转换一个小文件时,它可以工作,但当我使用一个较大的图像时,比如说1兆或更大,我得到 远程服务器返回意外响应:(413)请求实体太大。 我需要帮助 这是我的服务器端web.config <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriend
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<!--<bindings />-->
<bindings>
<basicHttpBinding>
<binding name="LargeSettings" maxReceivedMessageSize="2147483647">
<!--maxBufferSize="524288"
maxBufferPoolSize="524288"-->
<!--<readerQuotas maxDepth="32" maxStringContentLength="100000"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384"
/>-->
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name ="WCFService_VB1.StudentData"
behaviorConfiguration ="ServiceWithMetadata">
<endpoint name="Default"
address="http://www.ortho-sync.com:8080/StudentData.svc"
binding="basicHttpBinding"
bindingConfiguration="LargeSettings"
contract ="WCFService_VB1.IStudentData"/>
<!--<endpoint
address="mex"
binding="mexHttpBinding"
contract="WCFService_VB1.IStudentData"/>-->
</service>
</services>
<client />
<behaviors>
<serviceBehaviors>
<behavior name ="ServiceWithMetadata">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
my client side code is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IStudentData" maxReceivedMessageSize="2147483647" />
<binding name="BasicHttpBinding_IHeartbeat" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.ortho-sync.com:81/StudentData.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStudentData"
contract="oStudentData.IStudentData" name="BasicHttpBinding_IStudentData" />
<endpoint address="http://www.ortho-sync.com:81/StudentData.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHeartbeat"
contract="oStudentData.IHeartbeat" name="BasicHttpBinding_IHeartbeat" />
</client>
</system.serviceModel>
</configuration>
我的客户端代码是
可能的重复我认为您需要为maxBufferSize设置一个更高的值,defaut值为65536字节,这对于1 Mb的ImagemaxBufferSize来说是更小的。不应随意增加maxBufferSize,建议使用流传输模式(在绑定上设置transferMode=“streamed”)。这允许服务器在客户端仍在传输消息时开始处理该消息,而不是等待整个消息被传输,将整个消息放入内存,然后进行处理。我设置transferMode=“Streamed”1的配置的哪一部分。您不能仅仅将transferMode更改为流式传输,运营合同也需要处理流式传输。看见2.maxStringContentLength仅为100000(小于缓冲区大小),因此即使将缓冲区设置为更大的大小,如果消息长度超过1000000,也会遇到问题。