WCF通信问题

时间:2011-08-09 21:34:33

标签: c# wcf

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

如果我发送没有base64string(image)的字符串,我就能调试wcf服务代码。 但是,如果我添加base64String,我收到此错误。 我已将所有绑定值(“maxReceivedMessageSize”)和其他值增加到最大值。  我仍然得到这个错误。这是我的客户端和服务的web.config。  谢谢,我真的很感谢你的帮助。

客户端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>   

1 个答案:

答案 0 :(得分:1)

在web.config文件

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

希望这个帮助

相关问题