我想知道为什么 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 是这样设计的吗?
有没有办法解决这个限制?