为什么WCF类绑定没有';你没有会员阅读配额吗?

为什么WCF类绑定没有';你没有会员阅读配额吗?,wcf,binding,mex,readerquotas,Wcf,Binding,Mex,Readerquotas,我想知道为什么WCF中的类Binding没有属性ReaderQuotas,而它的子类BasicHttpBinding和WSHttpBinding有属性 这一事实使得编码有点困难。对于我来说,我使用下面的代码从MEX端点URI提取绑定信息。然而,它只是有约束力。如果我想更改绑定的ReaderQuotas,我必须将其向下转换为绑定的子类,但我无法在运行时说出确切的绑定 public static void LoadMex(string serviceMexUri, ContractDescr

我想知道为什么WCF中的类Binding没有属性ReaderQuotas,而它的子类BasicHttpBindingWSHttpBinding有属性

这一事实使得编码有点困难。对于我来说,我使用下面的代码从MEX端点URI提取绑定信息。然而,它只是有约束力。如果我想更改绑定的ReaderQuotas,我必须将其向下转换为绑定的子类,但我无法在运行时说出确切的绑定

public static void LoadMex(string serviceMexUri,
    ContractDescription contract,
    out EndpointAddress endpointAddress,
    out Binding serviceBinding)
{
    EndpointAddress mexAddress = new EndpointAddress(serviceMexUri);
    MetadataExchangeClient mexClient = new MetadataExchangeClient(mexAddress);
    mexClient.ResolveMetadataReferences = true;
    mexClient.OperationTimeout = TimeSpan.FromSeconds(30);

    MetadataSet metaSet = mexClient.GetMetadata();
    WsdlImporter importer = new WsdlImporter(metaSet);
    ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();

    foreach (ServiceEndpoint ep in endpoints)
    {
        // we just use one endpoint for now.
        if ((ep.Contract.Namespace == contract.Namespace) &&
             (ep.Contract.Name == contract.Name))
        {
            endpointAddress = new EndpointAddress(ep.Address.Uri);
            serviceBinding = ep.Binding;
            return;
        }
    }
    throw new ApplicationException(String.Format("no proper endpoint is found from MEX {0}", serviceMexUri));
}
有人知道为什么WCF是这样设计的吗


有什么方法可以绕过这个限制吗?

原因是绑定旨在作为通用通信基础设施发挥作用,而ReaderQuotas是一个特定于SOAP的对象。这就是为什么您只能在打算用于SOAP消息传输的绑定上看到它


“as”语句尝试转换到您想要支持的类型,这可能是您在这里的最佳选择。

读卡器配额是如何特定于SOAP的?充其量,它们是特定于XML的,即使如此,我也不太确定。考虑到JSon格式化程序是作为xml读写器在内部实现的,它们不也适用于JSon格式化程序吗?我检查了MSDN,似乎很多绑定子类都有readerquota,而不仅仅是SOAP绑定。