当前位置:编程学习 > C#/ASP.NET >>

WCF在传字符串大于8192个字符老是报错,测试了多种方法没有解决,求解

常规情况操作一切正常,只有客户端向WCF服务端发数据大于8192个字符时报错,急求解,谢谢!(联系QQ:363952092)

程序环境:VS2010、.Net4
//==========================================================================
WCF服务配置:
 <system.serviceModel>

    <client/>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IGroupWCFService"  maxBufferPoolSize="2147483647"
         maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="GJLV3.Web.WebServices.GroupWCFService" behaviorConfiguration="GJLV3.Web.WebServices.GroupWCFServiceBehaviors">
        <endpoint address="" binding="basicHttpBinding"   contract="GJLV3.Web.WebServices.IGroupWCFService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="GJLV3.Web.WebServices.GroupWCFServiceBehaviors">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

  </system.serviceModel>
  <applicationSettings>
    <GJLV3.Web.Properties.Settings>
      <setting name="GJLV3_Web_GroupMSWCFServiceE_GroupMSWCFService"
        serializeAs="String">
        <value>http://localhost:27910/CLL/WCFServices/GroupMSWCFService.svc</value>
      </setting>
    </GJLV3.Web.Properties.Settings>
  </applicationSettings>
//================================================================================
WCF客户端配置:
<system.serviceModel>
    <client>
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_WCF" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
          <security mode="None" />
        </binding>
        <binding name="NewBinding_WCF" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <applicationSettings>
    <GJLV3.Properties.Settings>
      <setting name="GJLV3_GroupWCFServiceE_GroupWCFService" serializeAs="String">
        <value>http://localhost:1542/WebServices/GroupWCFService.svc</value>
      </setting>
    </GJLV3.Properties.Settings>
  </applicationSettings>

//=============================================================================
报错内容:
{System.Web.Services.Protocols.SoapHeaderException: 格式化程序尝试对消息反序列化时引发异常: 对操作“WCFsetGroupInfo”的请求消息正文进行反序列化时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。 行 103,位置 2074。
   在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)



--------------------编程问答-------------------- 你的配置文件有点混乱。bind的名字都没有指定,应该是再用缺省值而不是你给的设定值。

检查一下:
1. 代码中是如何使用bind的,有没有指定configure的对应名称
2. 使用wsdl或者service reference比对一下自动生成的客户端配置文件和你使用的之间的差异
3. 必要时再看看MSDN中有关WCF配置的内容
4. 调试代码,看看实际使用的bind的配置 --------------------编程问答-------------------- 谢谢!我再学习学习! --------------------编程问答-------------------- 哎,跟你碰到了一样的问题 --------------------编程问答-------------------- 配置文件懒得看了,给你一段代码,经过验证的,可以传超大的对象:

 NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
 binding.MaxBufferSize = int.MaxValue;
 binding.MaxReceivedMessageSize = int.MaxValue;
 XmlDictionaryReaderQuotas quo = new XmlDictionaryReaderQuotas();
 binding.ReaderQuotas = quo;
 binding.ReaderQuotas.MaxArrayLength = 65536;
 binding.ReaderQuotas.MaxBytesPerRead = 10 * 1024 * 1024;
 binding.ReaderQuotas.MaxStringContentLength = 10 * 1024 * 1024; //65536;
           
 binding.ReceiveTimeout = TimeSpan.MaxValue;//设置连接自动断开的空闲时长;
 binding.MaxConnections = 100;
 binding.ListenBacklog = 200;
 binding.TransferMode = TransferMode.Buffered;

=========================================================
欢迎加入PDF.NET开源技术团队,做最快最轻的数据框架! --------------------编程问答-------------------- 只接分,楼上都说的很明白了,配置问题 --------------------编程问答-------------------- 楼主 你的客户端没有配置啊?代码里写的吗?
  

<client>
      <endpoint address="连接"
        binding="wsHttpBinding" bindingConfiguration="绑定"
        contract="ServiceReference1.IBusinessService" name="WSHttpBinding_IBusinessService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
--------------------编程问答-------------------- 呵呵,遇到与楼主一样的问题,还没解决,配置文件怎么改都不行。 --------------------编程问答-------------------- 我早已经解决 --------------------编程问答-------------------- 服务器端定义了 <binding name="BasicHttpBinding_IGroupWCFService"

但是没有使用

 <endpoint address="" binding="basicHttpBinding"   contract="GJLV3.Web.WebServices.IGroupWCFService" bindingConfiguration="BasicHttpBinding_IGroupWCFService" /> --------------------编程问答-------------------- 配置问题,不需要代码实现

引用 9 楼 findcaiyzh 的回复:
服务器端定义了 <binding name="BasicHttpBinding_IGroupWCFService"

但是没有使用

 <endpoint address="" binding="basicHttpBinding"   contract="GJLV3.Web.WebServices.IGroupWCFService" bindingConfigur……
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,