maxReceivedMessageSize

maxReceivedMessageSize

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

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



我的客户代码

<?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>

任何想法如何解决这个问题?

最佳答案

这可以解释。如果您查看自己的异常(exception)情况:

  • System.ServiceModel.CommunicationException是从客户端抛出的异常。它具有来自客户端的maxReceivedMessageSize。一切安好。
  • FaultException:此异常是SOAP错误,它将异常从服务传播到客户端应用程序。 (http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract)。因此,此异常实际上来自服务端! maxReceivedMessageSize是默认值,并且与服务器配置中的maxReceivedMessageSize不对应。
    您要在客户端中连接的地址是服务地址,未配置maxReceivedMessageSize,而不是配置为maxReceivedMessageSize =“2000000”的端点地址ConexaApi。这就是为什么要获得默认值65536的原因。

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

    10-05 23:02