简体   繁体   English

WCF maxReceivedMessageSize不能设置超过4215

[英]WCF maxReceivedMessageSize cant set over 4215

I want to set the maxReceivedMessageSize in the App.config of the WCF Client. 我想在WCF客户端的App.config中设置maxReceivedMessageSize。

If the maxReceivedMessageSize equals or is smaller then 4215 it works fine. 如果maxReceivedMessageSize等于或小于4215则可以正常工作。 Though when setting it to 4216 or any value above it, the default value of 65536 is taken. 虽然将其设置为4216或高于它的任何值时,将采用默认值65536。

在此输入图像描述

在此输入图像描述

My Client Code 我的客户代码

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

And The relavant Server Code 和相关的服务器代码

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

Any idea how to fix this? 知道如何解决这个问题吗?

This can be explainned. 这可以解释。 If you look at your exceptions: 如果你看看你的例外情况:

  • System.ServiceModel.CommunicationException is an exception thrown from client side. System.ServiceModel.CommunicationException是从客户端抛出的异常。 It has the maxReceivedMessageSize from the client side. 它具有来自客户端的maxReceivedMessageSize。 Everything is fine. 一切都好。
  • FaultException: this exception is a SOAP fault that propagate the exceptions from the service to the client application. FaultException:此异常是SOAP错误,它将异常从服务传播到客户端应用程序。 ( http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract ). http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract )。 So this exception is actually coming from the service side! 所以这个例外实际上来自服务方面! The maxReceivedMessageSize is the default value, and does not correspond to the maxReceivedMessageSize in your server configuration. maxReceivedMessageSize是默认值,与服务器配置中的maxReceivedMessageSize不对应。 The address you are connecting to in your client is the service address, not configured maxReceivedMessageSize, and not the endpoint address ConexaApi which is configure with maxReceivedMessageSize="2000000". 您在客户端中连接的地址是服务地址,未配置maxReceivedMessageSize,而不是使用maxReceivedMessageSize =“2000000”配置的端点地址ConexaApi。 That' s why you are getting the default 65536. 这就是你获得默认65536的原因。

And 4215 must be the size of your message if you consider that the exception does not raise if you increase it. 如果您认为如果增加异常,则4215必须与您的消息大小相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM