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?