当我尝试读取元数据时,我收到此错误,这里的任何想法都是我的代码
WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
binding.MaxReceivedMessageSize = Int32.MaxValue; // DPNote: This may actually be too big. see how it performs.
binding.ReaderQuotas.MaxNameTableCharCount = 99999999;
MetadataExchangeClientMode exchangeMode = MetadataExchangeClientMode.HttpGet; // Default to a HttpGET
metaClient = new MetadataExchangeClient(binding);
metaClient.MaximumResolvedReferences = 10 * 100; //DPNote: Some arbitrary number. Default is 10, so this is bigger.
if (address.Scheme == "http")
exchangeMode = MetadataExchangeClientMode.HttpGet;
else if (address.Scheme == "https")
exchangeMode = MetadataExchangeClientMode.HttpGet;
else
exchangeMode = MetadataExchangeClientMode.MetadataExchange;
MetadataSet metadata = metaClient.GetMetadata(address, exchangeMode);
MetadataImporter importer = new WsdlImporter(metadata);
这是抛出错误的行
MetadataSet metadata = metaClient.GetMetadata(address, exchangeMode);
答案 0 :(得分:6)
如果您通过visual studio执行“更新参考”,请将这些行添加到devenv.exe.config
<system.serviceModel>
<client>
<endpoint binding="netTcpBinding" bindingConfiguration="GenericBinding" contract="IMetadataExchange" name="net.tcp" />
</client>
<bindings>
<netTcpBinding>
<binding name="GenericBinding"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
答案 1 :(得分:2)
这是Microsoft代码中的错误,Http-Get不支持Reader Quotas,所以我们可以这样做
var smAsm = AppDomain.CurrentDomain.GetAssemblies().First(a => a.FullName.StartsWith("System.ServiceModel,"));
var defTy = smAsm.GetType("System.ServiceModel.Channels.EncoderDefaults");
var rq = (System.Xml.XmlDictionaryReaderQuotas)defTy.GetField("ReaderQuotas", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
rq.MaxArrayLength = int.MaxValue;
rq.MaxDepth = int.MaxValue;
rq.MaxNameTableCharCount = int.MaxValue;
rq.MaxStringContentLength = int.MaxValue;
答案 2 :(得分:0)
您是否尝试将binding.ReaderQuotas
内的任何其他值递增超出其默认值:
maxDepth,maxStringContentLength,maxArrayLength,maxBytesPerRead?
它也可能是binding
答案 3 :(得分:0)
问题似乎在.NET 4.0中得到修复。根据Reflector,MetadataExchangeClient现在从提供的绑定中读取配额,如果它没有,那么它将回退到EncoderDefaults。以前,我认为它只使用了EncoderDefaults,这就是为什么@ BreakHead的解决方案似乎是唯一的解决方案(用反射来改变EncoderDefaults)。