【问题标题】:WCF, Mtom Message Encoding, The maximum message size quota for incoming messages (65536) has been exceededWCF,Mtom 消息编码,已超过传入消息的最大消息大小配额 (65536)
【发布时间】:2020-03-18 05:31:11
【问题描述】:

让我从头开始解释。我的解决方案资源管理器窗口中有 3 个项目,位于 Visual Studio。让我一一解释。第一个是 Web 项目(基于 ASP.NET 表单)。我需要从 2 个不同的来源获取一些数据。因此,我在Visual Studio 的解决方案资源管理器窗口中添加了两个不同的 WCF 项目。

让我告诉你这两个 WCF 项目。第一个 WCF 连接到 SOAP Web 服务。此 SOAP 服务的消息编码类型应为 Mtom。顺便说一下,这个 SOAP Web 服务返回字节数据(如图片)。这就是为什么我右键单击然后添加>服务引用选项来完成此操作。 如您所知,此操作会自动更新 Web.config 文件。这就是为什么您会在 Web.config 文件中看到 'binding="wsHttpBinding" '。

除此之外,还有一个我上面提到的 WCF 项目。但这很好用。我没有任何问题。

我已通过右键单击添加>服务引用选项将这两个 WCF 项目添加到我的 Web 项目中。实际上它工作正常,直到我尝试使用大字节数据(图片)让我解释一下数据大小:第一个 WCF 项目能够为我带来一个小尺寸 1.84 KB(1,890 字节)的数据(图片)。但是同一个 WCF 项目无法为我带来更大尺寸 164 KB(168,423 字节)的数据(图片)。这就是问题。这就是为什么我共享了 web 项目的 web.config 文件和第一个 WCF 项目的 web.config 文件。

我正在共享显示大照片时出现错误的 web.config 文件。 (下面可以看到web项目的web.config文件和第一个WCF项目的web.config文件)

我已经创建并尝试了很多解决方案。但我仍然遇到同样的错误。

这是错误:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element

Web 服务器的 IIS 版本为:Windows Server 2012 R2,IIS:版本 8.5.9600.16384。我对这个问题进行了研究。我已经找到并尝试了很多解决方案。但它没有用。

这是 WCF 项目的 web.config 文件

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1"/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="abcdPortBinding">
          <mtomMessageEncoding messageVersion="Soap11" />
          <httpsTransport />
        </binding>
      </customBinding>
      <wsHttpBinding>
        <binding name="SecureHttpBinding" 
          closeTimeout="00:10:00" 
          openTimeout="00:10:00"
          sendTimeout="00:10:00" 
          maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647"
          messageEncoding="Mtom">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
          <security mode="None">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://abc.abc.com:443/abc-srv/abcPort"
        binding="customBinding" bindingConfiguration="abcdPortBinding"
        contract="mobilSignatureServiceReference.abcdsrv" name="abcdPort" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Servicebehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="Servicebehavior" name="abcdWcfServisi.abcdServisim">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="SecureHttpBinding" name="SecureHttp" contract="abcdWcfServisi.IabcdServisim"/>
        <host>
          <timeouts closeTimeout="00:10:00" openTimeout="00:10:00"/>
        </host>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

这里是web项目(asp.net form based project)的Web.config文件

<?xml version="1.0"?>
<configuration>
  <appSettings>
  </appSettings>
  <system.web>
    <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
    <machineKey validation="3DES"/>
    <pages viewStateEncryptionMode="Always" enableViewStateMac="true" controlRenderingCompatibilityVersion="4.0"/>
    <trace enabled="false" localOnly="true"/>
    <httpCookies httpOnlyCookies="true"/>
    <sessionState cookieless="UseCookies"/>
    <httpModules>
      <add name="myHttpModule" type="myHttpModule"/>
    </httpModules>
    <compilation debug="true" targetFramework="4.6.1">
      <assemblies>
        <add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms name="abc" loginUrl="login.aspx" defaultUrl="abc.aspx" timeout="50000"/>
    </authentication>
    <customErrors mode="RemoteOnly" defaultRedirect="https://abctest.com">
    </customErrors>
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    <validation validateIntegratedModeConfiguration="false"/>
    <defaultDocument>
      <files>
        <clear/>
        <add value="abc.aspx"/>
        <add value="abcSecureSrv.svc"/>
      </files>
    </defaultDocument>
    <httpErrors>
      <remove statusCode="502" subStatusCode="-1"/>
      <remove statusCode="501" subStatusCode="-1"/>
      <remove statusCode="500" subStatusCode="-1"/>
      <remove statusCode="412" subStatusCode="-1"/>
      <remove statusCode="406" subStatusCode="-1"/>
      <remove statusCode="405" subStatusCode="-1"/>
      <remove statusCode="403" subStatusCode="-1"/>
      <remove statusCode="401" subStatusCode="-1"/>
      <remove statusCode="404" subStatusCode="-1"/>
      <error statusCode="404" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="401" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="403" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="405" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="406" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="412" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="500" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="501" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
      <error statusCode="502" prefixLanguageFilePath="" path="https://abctest.com/abc.aspx" responseMode="Redirect"/>
    </httpErrors>
  </system.webServer>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HttpBinding_abcd" 
          closeTimeout="00:01:00"
          openTimeout="00:01:00" 
          receiveTimeout="00:10:00" 
          sendTimeout="00:10:00"
          maxBufferPoolSize="2147483647" 
          maxBufferSize="2147483647" 
          maxReceivedMessageSize="2147483647"
          textEncoding="utf-8" 
          transferMode="Streamed" 
          messageEncoding="Text" />
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="SecureHttp" messageEncoding="Mtom">
          <security mode="None" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://abctest.com/abcdesube.svc?wsdl"
        behaviorConfiguration="SertifikaDavranisi" binding="basicHttpBinding"
        bindingConfiguration="HttpBinding_abcd" contract="abcdesube"
        name="HttpBinding_abcd" />
      <endpoint address="http://localhost:37377/abcdServisim.svc" binding="wsHttpBinding"
        bindingConfiguration="SecureHttp" contract="abcdSignature.IabcdServisim"
        name="SecureHttp" />
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SertifikaDavranisi">
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="SertifikaDavranisi">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我该如何解决这个问题?

【问题讨论】:

    标签: asp.net wcf web-config


    【解决方案1】:

    如何通过添加服务引用来调用服务?您似乎在 web 项目中调用了该服务。但是为什么 WCF 项目有 Client 部分?这表明 WCF 项目已经引用了其他项目。
    我想知道您在客户端调用服务的详细步骤,包括您输入的服务元数据 URL。
    此外,尝试删除所有其他不相关的项目配置并重新添加服务引用并与我分享。这些配置似乎不是自动生成的。
    期待您的回复。
    已更新。
    我建议您创建一个新的控制台应用程序再次测试并删除 WCF 项目中不相关的配置。请用以下代码替换system.servicemodel 配置。

    <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="mybinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
              <security mode="None">
              </security>
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
            </binding>
          </wsHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <protocolMapping>
          <add binding="wsHttpBinding" scheme="http" bindingConfiguration="mybinding"/>
        </protocolMapping>
      </system.serviceModel>
    

    如果问题仍然存在,请随时告诉我。

    【讨论】:

    • 感谢您的回复。我已经按照你说的更新了我的帖子。
    • 为什么你的 WCF 项目的第一个 Webconfig 文件有客户端部分?它是否生成客户端代理并从中获取数据?我们是否可能需要在此绑定上应用设置,即 Custombidning?此外,您的 Web 项目的 webconfig 文件中有两个客户端服务端点。你调用哪一个返回图片的数据?
    • 您的第一个问题:为什么您的 WCF 项目的第一个 Webconfig 文件有客户端部分?首先我创建了一个 Web 项目,然后我添加了一个 WCF 项目。然后右键单击 WCF Project>Service Reference 选项。我写了 SOAP 链接,它在这个窗口中返回我的图片数据。我已经以这种方式完成了添加服务参考。所有这些操作都自动创建了这个 web.config 文件(我的帖子中的第一个 web 配置文件)我没有更改这个 web.config 文件的任何内容。 @亚伯拉罕·钱
    • 您的第二个问题:此外,您的Web项目的webconfig文件中有两个客户端服务端点。你调用哪一个返回图片的数据?回复如下: 这个:localhost:37377/abcdServisim.svc" binding="wsHttpBinding" bindingConfiguration="SecureHttp" contract="abcdSignature.IabcdServisim" name="SecureHttp" /> 当然我改了真实地址链接和由于公司不允许共享,因此与虚拟事物的合同细节。
    • 整体配置好像没有什么问题,虽然客户端配置不是必须的,但是尽量把你的配置应用到客户端的wshttpbinding上。
    【解决方案2】:

    &lt;httpsTransport..&gt;标签解决了这个问题。

    <customBinding>
    <binding> 
     <httpsTransport maxReceivedMessageSize="2147483647"/>    
     </binding>
    </customBinding>
    

    【讨论】:

      猜你喜欢
      • 2013-11-03
      • 2014-02-01
      • 2014-10-23
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多