WCF DefaultBinding未在新WsHttpBinding上使用

WCF DefaultBinding未在新WsHttpBinding上使用,wcf,wcf-binding,wshttpbinding,wcf-wshttpbinding,readerquotas,Wcf,Wcf Binding,Wshttpbinding,Wcf Wshttpbinding,Readerquotas,我有一个第三方库,在特定的端点连接到webservice。 对于某些服务,我得到以下例外情况: Message=The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML

我有一个第三方库,在特定的端点连接到webservice。 对于某些服务,我得到以下例外情况:

Message=The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 1339.
解决办法是,增加阅读量。 WCF建议通过配置文件执行此操作

我的app.config现在看起来像:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding>
          <readerQuotas maxNameTableCharCount="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>   
  </system.serviceModel>
</configuration>
我遗漏了什么?

你尝试过这个链接吗

这是我们代码中的一个bug(您传递的绑定会被忽略) HTTP-GET)。有一些变通办法

你能看看他们中是否有人会为你工作吗

  • 该服务是WCF服务吗?如果是,您可以在服务上启用mex端点吗?绑定将用于mex端点的工作。 能
  • 您使用的是发现协议() 要从您的服务中获取元数据?此应用程序使用的XML读取器
    类没有任何配额

WSHttpBinding x=新的WSHttpBinding()
使用框架默认值创建
WSHttpBinding
的新实例。即使您在配置文件中定义了默认绑定配置,代码也不会使用它(有关源代码,请参阅)。换句话说,调用
WSHttpBinding
的无参数构造函数不会应用任何相关配置文件中的默认绑定,至少我可以看到

你有几个选择。首先,在配置文件中为绑定配置指定一个名称,并引用该名称。第二,当您以编程方式创建绑定时,将值分配给
XmlDictionaryReaderQuotas

选择1

<bindings>
  <wsHttpBinding>
    <binding name="MyBinding">
      <readerQuotas maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

WSHttpBinding x = new WSHttpBinding("MyBinding");

你试过这个吗?我查过了。。。但是没有让它工作,所以我试着用几行代码来简化它,并使用app.configohh。。。。问题是,我们使用的第三方DLL(acutally MS CRM 2013 SDK)中的代码是这样的。使用reflector,我发现那里的绑定类似于:returnnewWSHttpBinding(SecurityMode.None,false){Name=“MetadataExchangeHttpBinding”,Namespace=”“};有没有办法更改此绑定?我想not as Name不是作为参数传递的,而是在{}中设置的。提前非常感谢@kamahl-不幸的是,在第三方DLL中没有简单的方法来更改绑定。如果在客户端接收到错误(即,当客户端尝试反序列化响应时),您可以更改客户端绑定定义上的配额,但如果您从服务接收到此错误,您将处于更困难的位置。您可以尝试减少期望从服务返回的信息量,但这可能会很快变成一个漫长而痛苦的猜测游戏。您好,我是第三方dll的客户端,我们没有特定绑定,但dll在运行时发现连接,并使用system.servicemodel.metadataclient获取元数据。这个坏了,嗨。谢谢你的链接!这对我来说是新的信息。看起来这个错误已经解决了,但我会继续思考的!
<bindings>
  <wsHttpBinding>
    <binding name="MyBinding">
      <readerQuotas maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

WSHttpBinding x = new WSHttpBinding("MyBinding");
WSHttpBinding x = new WSHttpBinding();
x.ReaderQuotas rq = new XmlDictionaryReaderQuotas();
rq.MaxNameTableCharCount = Int32.MaxValue;