简体   繁体   English

为什么WCF类绑定没有成员ReaderQuotas?

[英]Why WCF class Binding doesn't have member ReaderQuotas?

I'm wondering why the class Binding in WCF doesn't have a property ReaderQuotas , while its subclasses BasicHttpBinding and WSHttpBinding does. 我想知道为什么WCF中的Binding类没有属性ReaderQuotas ,而其子类BasicHttpBindingWSHttpBinding却具有。

This fact makes coding a little hard. 这个事实使编码有些困难。 For me, I use below code to extract binding information from MEX endpoint URI. 对我来说,我使用下面的代码从MEX端点URI中提取绑定信息。 However, it just got Binding. 但是,它只是具有绑定功能。 If I want to change ReaderQuotas of the binding, I have to downcast it to subclasses of Binding , but I cannot tell the exact binding at runtime. 如果要更改绑定的ReaderQuotas ,则必须将其转换为Binding的子类,但是我无法在运行时知道确切的绑定。

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));
}

Anybody know why WCF is designed in such way? 有人知道为什么WCF是这样设计的吗?

Is there any way to work around this limitation? 有什么办法可以解决此限制?

The reason is that bindings are intended to function as generic communication infrastructure and ReaderQuotas is a SOAP specific object. 原因是绑定旨在用作通用的通信基础结构,而ReaderQuotas是SOAP特定的对象。 This is why you only see it on the bindings that are intended to be used with SOAP message transfers. 这就是为什么您只在打算与SOAP消息传输一起使用的绑定上看到它的原因。

An "as" statement to try the cast to the types you want to support is probably your best option here. 尝试将类型转换为要支持的类型的“ as”语句可能是此处的最佳选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM