WCF,Mtom 消息编码,已超过传入消息的最大消息大小配额 (65536)
WCF, Mtom Message Encoding, The maximum message size quota for incoming messages (65536) has been exceeded
让我从头给你解释。 Visual Studio
中我的解决方案资源管理器 window 中有 3 个项目。让我一一解释。第一个是 Web 项目(ASP.NET 基于表单)。我需要从两个不同的来源获取一些数据。因此,我在 Visual Studio
.
中的解决方案资源管理器 window 中添加了两个不同的 WCF 项目
让我告诉您这 2 个 WCF 项目。首先 WCF 连接到 SOAP Web 服务。对于此 SOAP 服务,消息编码类型应该是 Mtom。顺便说一句,这个 SOAP 网络服务 returns 字节数据(如图片)。这就是为什么我右击然后添加>服务引用选项来完成这个操作。
如您所知,此操作会自动更新 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项目的Web.config文件(asp.net基于表单的项目)
<?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>
我该如何解决这个问题?
如何通过添加服务引用来调用服务?看来你在 web 项目中调用了服务。但为什么 WCF 项目有客户端部分?这说明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>
如果问题仍然存在,请随时告诉我。
<httpsTransport..>
标签已解决问题。
<customBinding>
<binding>
<httpsTransport maxReceivedMessageSize="2147483647"/>
</binding>
</customBinding>
让我从头给你解释。 Visual Studio
中我的解决方案资源管理器 window 中有 3 个项目。让我一一解释。第一个是 Web 项目(ASP.NET 基于表单)。我需要从两个不同的来源获取一些数据。因此,我在 Visual Studio
.
让我告诉您这 2 个 WCF 项目。首先 WCF 连接到 SOAP Web 服务。对于此 SOAP 服务,消息编码类型应该是 Mtom。顺便说一句,这个 SOAP 网络服务 returns 字节数据(如图片)。这就是为什么我右击然后添加>服务引用选项来完成这个操作。 如您所知,此操作会自动更新 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项目的Web.config文件(asp.net基于表单的项目)
<?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>
我该如何解决这个问题?
如何通过添加服务引用来调用服务?看来你在 web 项目中调用了服务。但为什么 WCF 项目有客户端部分?这说明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>
如果问题仍然存在,请随时告诉我。
<httpsTransport..>
标签已解决问题。
<customBinding>
<binding>
<httpsTransport maxReceivedMessageSize="2147483647"/>
</binding>
</customBinding>