【问题标题】:Why WCF class Binding doesn't have member ReaderQuotas?为什么 WCF 类绑定没有成员 ReaderQuotas?
【发布时间】:2008-11-17 02:48:56
【问题描述】:

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

这一事实使编码有点困难。对我来说,我使用下面的代码从 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 是这样设计的吗?

有什么办法可以解决这个限制吗?

【问题讨论】:

    标签: wcf binding mex readerquotas


    【解决方案1】:

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

    尝试强制转换为您想要支持的类型的“as”语句可能是您最好的选择。

    【讨论】:

    • 阅读器配额 SOAP 的具体情况如何?充其量,它们是特定于 XML 的,即便如此,我也不太确定。考虑到它们是作为 xml 读取器/写入器在内部实现的,它们是否也适用于 JSon 格式化程序?
    • 我查了 MSDN,似乎很多 Binding 子类都有 ReaderQuotas,而不仅仅是 SOAP 绑定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多