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具有要求的实例。

适用于