WCF通信问题

本文关键字:问题 通信 WCF | 更新日期: 2023-09-27 18:05:06

在我的WCF应用程序中,我收到base64String格式的图像以及其他一些图像。为了测试我的应用程序,我创建了一个小的.aspx页面,它将发送名字,姓氏和base64string(图像:大小10Kb)到WCF服务。我得到了错误格式化程序在试图反序列化消息时抛出异常:对操作"SaveData"的请求消息体进行反序列化时出错。读取XML数据时已超过最大字符串内容长度配额(8192)。的MaxStringContentLength属性可以增加此配额创建XML阅读器时使用的xmldictionaryreaderquota对象。1号线,位置15301。"

如果我发送没有base64string(图像)的字符串,我能够调试wcf服务代码。但如果我添加base64String我得到这个错误。我增加了所有绑定值("maxReceivedMessageSize")和其他值到最大值。我还是会得到这个错误。这是我的网。配置客户端和服务。谢谢,我真的很感谢你的帮助。

客户机web . config

 <system.serviceModel>  
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IRESTService1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:10255/RESTService1.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IRESTService1" contract="ServiceReference1.IRESTService1"
        name="BasicHttpBinding_IRESTService1" />
    </client>
  </system.serviceModel>
服务web . config

<system.serviceModel>       
    <bindings>
      <basicHttpBinding>
        <binding name="BasicBinding1" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>      
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="RESTService1">
        <endpoint address=""
          binding="basicHttpBinding" name="MainHttpPoint" contract="RESTService1"  bindingConfiguration="BasicBinding1" />       
      </service>
    </services>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>   

WCF通信问题

将这些行添加到web中的Binding标记中。配置文件

<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"   maxBytesPerRead="2147483647" />
</binaryMessageEncoding>
<httpTransport  decompressionEnabled="True" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>

MSDN: binaryMessageEncoding

希望对您有所帮助