【问题标题】:WCF communication problemWCF 通信问题
【发布时间】:2011-08-09 21:34:32
【问题描述】:

在我的 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>   

【问题讨论】:

    标签: c# wcf


    【解决方案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

    希望有帮助

    【讨论】:

    • 您好阿玛尼,感谢您的回复。但它不允许我在 标记内添加 标记。知道我应该在哪里添加它。
    • 朋友我说的是Binding标签,不是Bindings。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 2017-07-13
    相关资源
    最近更新 更多