首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么WCF类绑定没有成员ReaderQuotas?

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

Stack Overflow用户
提问于 2008-11-17 02:48:56
回答 1查看 1.5K关注 0票数 1

我想知道为什么WCF中的类BasicHttpBinding绑定没有属性ReaderQuotas,而它的子类和WSHttpBinding却有。

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

代码语言:javascript
复制
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是这样设计的吗?

有办法解决这个限制吗?

EN

回答 1

Stack Overflow用户

发布于 2008-11-17 19:59:15

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

在这里,使用"as“语句尝试将类型转换为您想要支持的类型可能是最好的选择。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/294774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档