1
我有一個WCF服務,Server
,它接受來自控制檯應用程序Client
的請求。當發送數據(這是比較大的),我得到以下異常:與WCF服務通話時獲取「413請求實體太大」
System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (413) Request Entity Too Large. ---> System.Net.WebException: The remote server returned an error: (413) Request Entity Too Large.
我原本以爲在配置文件中正確設置的限制,但顯然我錯了?
這裏的Server
的相關部分的app.config
:
<system.serviceModel>
<services>
<service name="Services.Server">
<endpoint bindingConfiguration="LargeWeb" binding="webHttpBinding" contract="Interfaces.IServer" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="LargeWeb" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
而這裏的Client
的app.config
:
<system.serviceModel>
<client>
<endpoint name="serverEndpoint" binding="webHttpBinding" bindingConfiguration="LargeWeb" contract="Interfaces.IServer" />
</client>
<bindings>
<webHttpBinding>
<binding name="LargeWeb" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
最後,這是多麼Client
調用Server
的方法:
using (var cf = new WebChannelFactory<IServer>("serverEndpoint", serverAddress))
{
var channel = cf.CreateChannel();
channel.SomeMethod(some, arguments);
}
我在做什麼錯?
謝謝你的幫助。
您需要具有maxReceivedMessageSize大小以更正大小。正如你所提到的,你在你的配置中有設置。你可以檢查你期望使用Fiddler的kb的響應大小是多少? – Agalo
@Agalo,我現在無法檢查,但尺寸肯定高達〜10兆,即相對較大,但沒有真正的極端。只需在配置文件中設置maxReceivedMessageSize是不夠的?謝謝! – liszt
2147483647是字節數,等於〜2 GB。對於任何更大的內容,請查看[streaming](https://msdn.microsoft.com/en-us/library/ms733742(v = vs.110).aspx)或[chunking](https://msdn.microsoft。 COM/EN-US /庫/ aa717050(v = vs.110)的.aspx)。 – Tim