繁体   English   中英

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

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

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

这个事实使编码有些困难。 对我来说,我使用下面的代码从MEX端点URI中提取绑定信息。 但是,它只是具有绑定功能。 如果要更改绑定的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));
}

有人知道为什么WCF是这样设计的吗?

有什么办法可以解决此限制?

原因是绑定旨在用作通用的通信基础结构,而ReaderQuotas是SOAP特定的对象。 这就是为什么您只在打算与SOAP消息传输一起使用的绑定上看到它的原因。

尝试将类型转换为要支持的类型的“ as”语句可能是此处的最佳选择。

暂无
暂无

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

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