BindingElement.GetProperty<T>(BindingContext) 方法

定义

在派生类中重写时,从绑定堆栈的适当层返回所请求的类型化对象(如果存在)。

public:
generic <typename T>
 where T : class abstract T GetProperty(System::ServiceModel::Channels::BindingContext ^ context);
public abstract T GetProperty<T> (System.ServiceModel.Channels.BindingContext context) where T : class;
abstract member GetProperty : System.ServiceModel.Channels.BindingContext -> 'T (requires 'T : null)
Public MustOverride Function GetProperty(Of T As Class) (context As BindingContext) As T

类型参数

T

方法正在查询的类型化对象。

参数

context
BindingContext

绑定元素的 BindingContext

返回

T

如果存在,则返回所请求的类型化对象 T,如果不存在,则返回 null

示例

CustomBinding binding = new CustomBinding();
HttpTransportBindingElement element = new HttpTransportBindingElement();
BindingParameterCollection parameters = new BindingParameterCollection();
parameters.Add(new ServiceCredentials());
Uri baseAddress = new Uri("http://localhost:8000/ChannelApp");
String relAddress = "http://localhost:8000/ChannelApp/service";
BindingContext context = new BindingContext(binding, parameters, baseAddress, relAddress, ListenUriMode.Explicit);

ServiceCredentials serviceCredentials = element.GetProperty<ServiceCredentials>(context);

注解

使用此方法可以从绑定元素堆栈中检索功能、需求和参数。 如果绑定元素支持返回所请求的对象,则会返回对象。 如果不支持,就会将调用委托给堆栈中的下一个绑定元素。 如果到达堆栈底部仍然没有绑定元素支持所请求的对象,则该方法返回 null

备注

如果要添加的消息头必须加密,则必须在要求 ChannelProtectionRequirements 时,从此方法返回具有您的要求的 ChannelProtectionRequirements 实例。

适用于