1

I'm wondering why the class Binding in WCF doesn't have a property ReaderQuotas, while its subclasses BasicHttpBinding and WSHttpBinding does.

This fact makes coding a little hard. For me, I use below code to extract binding information from MEX endpoint 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.

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?

Is there any way to work around this limitation?

4

1 に答える 1

0

その理由は、バインディングは一般的な通信インフラストラクチャとして機能することを目的としており、ReaderQuotasはSOAP固有のオブジェクトであるためです。これが、SOAPメッセージ転送で使用することを目的としたバインディングでのみ表示される理由です。

サポートしたいタイプへのキャストを試すための「as」ステートメントは、おそらくここでの最良のオプションです。

于 2008-11-17T19:59:15.953 に答える