c# - WCF maxReceivedMessageSize 不能设置超过 4215

标签 c# wcf app-config

我想在 WCF 客户端的 App.config 中设置 maxReceivedMessageSize。

如果 maxReceivedMessageSize 等于或小于 4215,则它工作正常。尽管将其设置为 4216 或高于它的任何值时,将采用默认值 65536。

enter image description here

enter image description here

我的客户端代码

<?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_IConexaApiServic" maxReceivedMessageSize="4216" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://svsr02.conexa.local/HelloService/ConexaApiService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConexaApiServic"
                contract="ConexaApiService.IConexaApiService" name="BasicHttpBinding_IConexaApiService" />
        </client> 
    </system.serviceModel>
</configuration>

和相关的服务器代码

<basicHttpBinding>
        <binding name="BasicHttpEndpoint_MPSAPIServic" maxReceivedMessageSize="2000000">
          <security mode="TransportWithMessageCredential" />
        </binding>
        <binding name="BasicHttpEndpoint_HelloService" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2000000">

  </binding>
   </basicHttpBinding>

 <service name="IIS_test123.HelloService">
        <endpoint address="ConexaApi" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint_HelloService" contract="IIS_test123.IHelloService"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/API/ConexaApiService" />
          </baseAddresses>
        </host>
      </service>
    </services>

知道如何解决这个问题吗?

最佳答案

这可以解释。如果您查看异常:

  • System.ServiceModel.CommunicationException 是客户端抛出的异常。它具有来自客户端的 maxReceivedMessageSize。一切都很好。
  • FaultException:此异常是一个 SOAP 错误,它将异常从服务传播到客户端应用程序。 (http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract)。所以这个异常其实是来自服务端的! maxReceivedMessageSize 是默认值,与服务器配置中的 maxReceivedMessageSize 不对应。 您在客户端连接的地址是服务地址,不是配置的 maxReceivedMessageSize,也不是配置了 maxReceivedMessageSize="2000000"的端点地址 ConexaApi。这就是您获得默认值 65536 的原因。

并且 4215 必须是您的消息的大小,如果您认为增加它不会引发异常。

关于c# - WCF maxReceivedMessageSize 不能设置超过 4215,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28453765/

相关文章:

c# - Lambda 作为参数

c# - C# 中的动态与 var

wcf - WCF 服务(托管在 IIS 中)出现 20 个并发请求的性能问题

c# - WCF - 在没有客户端调用的情况下发送回调

c# - 是否可以将应用程序配置中的更改序列化到应用程序的 app.config 文件中?

c# - C#中的委托(delegate)和继承

c# - 发布到 mvc actionresult 时,Json 数组对象始终为空

.net - 希望创建客户端应用程序 (WPF) 来对远程数据执行 CRUD 操作

c# - ConfigurationManager.AppSettings - 返回 Null

.net - 部署通过 app.config 中的 RSAProtectedConfigurationProvider 加密的连接字符串