WCF学习笔记三:使用自定义行为扩展WCF总结

服务站: 使用自定义行为扩展 WCF文中详细的描述了自定义行为扩展点,下面对这些扩展点的扩展方法进行总结

 

调度程序扩展点
1、消息检查:EndpointDispatcher.DispatchRuntime.MessageInspectors.Add(IDispatchMessageInspector);
2、操作选择器:EndpointDispatcher.DispatchRuntime.OperationSelector = IDispatchOperationSelector;
3、消息格式化(反序列化):DispatchOperation.Formatter = IDispatchMessageFormatter;
4、参数检查:DispatchOperation.ParameterInspectors.Add(IparameterInspector);
5、操作调用程序:DispatchOperation.Invoker = IOperationInvoker;

 

获取DispatchRuntime实例的几种方式【DispatchRuntime 类

a、在ServiceHost中

 
  
foreach (ChannelDispatcher cDispatcher in host.ChannelDispatchers)
foreach (EndpointDispatcher endpointDispatcher in cDispatcher.Endpoints)
endpointDispatcher.DispatchRuntime...

 

b、在IServiceBehavior接口的ApplyDispatchBehavior中

 
  
public void ApplyDispatchBehavior(ServiceDescription serviceDescription,

System.ServiceModel.ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcher cDispatcher in serviceHostBase.ChannelDispatchers)
foreach (EndpointDispatcher endpointDispatcher in cDispatcher.Endpoints)
endpointDispatcher.DispatchRuntime...
}

 

c、在IEndpointBehavior接口的ApplyDispatchBehavior中

 
  
public void ApplyDispatchBehavior(ServiceEndpoint endpoint,

System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.DispatchRuntime...
}

 
d、在IContractBehavior接口的ApplyDispatchBehavior中

 
  
public void ApplyDispatchBehavior(ContractDescription contractDescription,

ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatchRuntime)
{
dispatchRuntime...
}

 

 获取DispatchOperation实例的几种方式【DispatchOperation类
a、在IOperationBehavior接口的ApplyDispatchBehavior中

 
  
public void ApplyDispatchBehavior(OperationDescription operationDescription,

System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation)
{
dispatchOperation...
}

 
b、在DispatchRuntime实例中

 
  
foreach (DispatchOperation dispatchOperation in DispatchRuntime.Operations)
dispatchOperation...


代理(客户端)扩展点
1、参数检查:ClientOperation.ParameterInspectors.Add(IparameterInspector);
2、消息格式化(序列化):ClientOperation.Formatter = IClientMessageFormatter;
?、操作选择器:ClientRuntime.OperationSelector = IClientOperationSelector;
3、消息检查:ClientRuntime.MessageInspectors.Add(IClientMessageInspector);

 

获取ClientRuntime实例的几种方式【ClientRuntime类
a、在IEndpointBehavior接口的ApplyClientBehavior中

 
  
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime...
}

 
b、在IContractBehavior接口的ApplyClientBehavior中

 
  
public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint

endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
clientRuntime...
}

 

获取ClientOperation实例的几种方式【ClientOperation类
a、在IOperationBehavior接口的ApplyClientBehavior中

 
  
public void ApplyClientBehavior(OperationDescription operationDescription,

System.ServiceModel.Dispatcher.ClientOperation clientOperation)
{
clientOperation...
}


b、在ClientRuntime实例中

 
  
foreach (ClientOperation clientOperation in ClientRuntime.Operations)
clientOperation...


I...Behavior添加到ServiceHost中的方法
1、IServiceBehavior

 
  
ServiceHost.Description.Behaviors.Add(IServiceBehavior);


2、IEndpointBehavior

 
  
foreach (ServiceEndpoint endpoint in ServiceHost.Description.Endpoints)
{
endpoint.Behaviors.Add(IEndpointBehavior);
}


3、IContractBehavior

 
  
foreach (ServiceEndpoint endpoint in ServiceHost.Description.Endpoints)
{
endpoint.Contract.Behaviors.Add(IContractBehavior);
}


4、IOperationBehavior

 
  
foreach (ServiceEndpoint endpoint in ServiceHost.Description.Endpoints)
{
foreach (OperationDescription operationDescription in endpoint.Contract.Operations)
{
operationDescription.Behaviors.Add(IOperationBehavior);
}
}

 

I...Behavior添加到Client的Endpoint中的方法
1、IEndpointBehavior

 
  
Endpoint.Behaviors.Add(IEndpointBehavior);


2、IContractBehavior

 
  
Endpoint.Contract.Behaviors.Add(IContractBehavior);


3、IOperationBehavior

 
  
foreach (OperationDescription operationDescription in Endpoint.Contract.Operations)
{
operationDescription.Behaviors.Add(IOperationBehavior);
}


获取Client的Endpoint的方法:
1、ClientBase.Endpoint
2、ChannelFactory.Endpoint

 

转载于:https://www.cnblogs.com/xujiaoxiang/archive/2010/06/03/1750726.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值