我想知道为什么WCF中的类BasicHttpBinding绑定没有属性ReaderQuotas,而它的子类和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是这样设计的吗?
有办法解决这个限制吗?
发布于 2008-11-17 19:59:15
原因是绑定的目的是作为通用通信基础设施,而ReaderQuotas是SOAP特定的对象。这就是为什么您只在希望与SOAP消息传输一起使用的绑定上看到它。
在这里,使用"as“语句尝试将类型转换为您想要支持的类型可能是最好的选择。
https://stackoverflow.com/questions/294774
复制相似问题