转 使用IParameterInspector, IOperationBehavior,Attribute(参数检查器、操作行为接口和标签)扩展WCF操作行为
public class EntryIdInspector : IParameterInspector
{
public int intParamIndex
{
get;
set;
}
string EntryIdFormat = @"\d{17}"; public EntryIdInspector(): this(0){ } public EntryIdInspector(int intParamIndex)
{
this.intParamIndex = intParamIndex;
} public object BeforeCall(string operationName, object[] inputs)
{
string strEntryId = inputs[this.intParamIndex] as string;
if (!Regex.IsMatch(strEntryId, this.EntryIdFormat, RegexOptions.None))
{ MessageQueue mq = new MessageQueue(@".\private$\msgqueue");
mq.Send( "Parameter is not valid when call " + operationName + " at " + DateTime.Now.ToLongDateString());
throw new FaultException(
"Invalid Entry ID format. Required format: ##################");
}
return null; }
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
MessageQueue mq = new MessageQueue(@".\private$\msgqueue");
string strResult = returnValue.ToString();
mq.Send("Client call " + operationName + ":" + strResult + " at " + DateTime.Now.ToLongDateString()); }
}
public class EntryIdValidation : Attribute, IOperationBehavior
{
#region IOperationBehavior Members public void AddBindingParameters(OperationDescription operationDescription,
BindingParameterCollection bindingParameters)
{
} public void ApplyClientBehavior(OperationDescription operationDescription,
ClientOperation clientOperation)
{
EntryIdInspector EntryIdInspector = new EntryIdInspector();
clientOperation.ParameterInspectors.Add(EntryIdInspector);
} public void ApplyDispatchBehavior(OperationDescription operationDescription,
DispatchOperation dispatchOperation)
{
EntryIdInspector EntryIdInspector = new EntryIdInspector();
dispatchOperation.ParameterInspectors.Add(EntryIdInspector);
} public void Validate(OperationDescription operationDescription)
{
} #endregion
}
在操作Operation上加入标签attribute,在操作契约中加上标签[EntryIdValidation]
[ServiceContract]
public interface IRelSrvContract
{
[EntryIdValidation]
[OperationContract]
bool Rel(string strEntryID);
}
转 使用IParameterInspector, IOperationBehavior,Attribute(参数检查器、操作行为接口和标签)扩展WCF操作行为的更多相关文章
- golang 防SQL注入 基于反射、TAG标记实现的不定参数检查器
收到一个任务,所有http的handler要对入参检查,防止SQL注入.刚开始笨笨的,打算为所有的结构体写一个方法,后来统计了下,要写几十上百,随着业务增加,以后还会重复这个无脑力的机械劳作.想想就l ...
- 自研后端HTTP请求参数验证器服务ParamertValidateService
好处:方便了后端对HTTP请求中参数进行核验,只需一次编写效验器,一行代码便可对所有参数的pojo进行参数核验!而且更改效验逻辑时只需要更改效验器类即可,实现了解耦合. 只需要程序员按照规范开发一个P ...
- 实现自定义的参数解析器——HandlerMethodArgumentResolver
1.为什么需要自己实现参数解析器 我们都知道在有注解的接口方法中加上@RequestBody等注解,springMVC会自动的将消息体等地方的里面参数解析映射到请求的方法参数中. 如果我们想要的信息不 ...
- SpringMVC 自定义参数解析器.
一.简述 有没有想过像 @RequestParam.@RequestBody 这些注解的工作原理呢?为什么 form 表单.application/json 的参数能够直接封装进 Bean 对象中呢? ...
- 一步一步自定义SpringMVC参数解析器
随心所欲,自定义参数解析器绑定数据. 题图:from Zoommy 干货 SpringMVC解析器用于解析request请求参数并绑定数据到Controller的入参上. 自定义一个参数解析器需要实现 ...
- python 拼写检查代码(怎样写一个拼写检查器)
原文:http://norvig.com/spell-correct.html 翻译:http://blog.youxu.info/spell-correct.html 怎样写一个拼写检查器 Pete ...
- SpringMVC自动封装List对象 —— 自定义参数解析器
前台传递的参数为集合对象时,后台Controller希望用一个List集合接收数据. 原生SpringMVC是不支持,Controller参数定义为List类型时,接收参数会报如下错误: org.sp ...
- 如何写一个拼写检查器-by Peter Norvig
本文原著:Peter Norvig 中文翻译:徐宥 上个星期, 我的两个朋友 Dean 和 Bill 分别告诉我说他们对 Google 的快速高质量的拼写检查工具感到惊奇. 比如说在搜索的时候键入 ...
- 实现一个可配置的java web 参数验证器
当使用java web的servlet来做接口的时候,如果严格一点,经常会对请求参数做一些验证并返回错误码.我发现通常参数验证的代码就在servlet里边,如果参数不正确就返回相应的错误码.如果接口数 ...
随机推荐
- Android开发Camera2相关
Android自定义相机 https://github.com/miqt/camera2 Camera2必知必会 https://www.cnblogs.com/fuyaozhishang/p/975 ...
- 002 centos7中遇到的问题
在关机的时候,发现输入密码之后竟然报错了,然后确认普通用户的密码没有问题.下面是处理方式. 一:问题 1.问题 当在终端执行sudo命令时,系统提示“caojun is not in the sudo ...
- lua:写了个基于协程的task调度库
写了一个(不完整的)基于协程的task调度库 sample code如下 my_spawn( function () print('f: 1') local t1 = my_spawn( functi ...
- 002——Angular 目录结构分析、app.module.ts 详解、以及 Angular 中创建组件、组件 详解、 绑定数据
一.目录结构分析 二. app.module.ts.组件分析 1.app.module.ts 定义 AppModule,这个根模块会告诉 Angular 如何组装该应用. 目前,它只声明了 AppCo ...
- php 微信公众平台OAuth2.0网页授权,获取用户信息代码类封装demo
get_wx_data.php <?php /** * 获取微信用户信息 * @author: Lucky hypo */ class GetWxData{ private $appid = ' ...
- Go 包导入备忘
一 包的导入语法 在写Go代码的时候经常用到import这个命令用来导入包文件,看到的方式参考如下: import( "fmt" ) ...
- ubuntu 18.04使用sysbench测试MySQL性能
首先下载安装sysbench: sudo apt-get install sysbench -y 查看一下sysbench版本是多少: zifeiy@zifeiy-S1-Series:~$ sysbe ...
- 【tensorflow】tensorflow官网进不去,因为它的地址改变了
以前的网址是https://www.tensorflow.org/,当时得fq才能打开,现在这个我fq都打不开了. 现在新网址是https://tensorflow.google.cn/这个不fq都可 ...
- Nodejs Client for FastDFS
FastDFS 是分布式文件存储系统.这个项目是FastDFS的NodeJS客户端,用来与FastDFS Server进行交互,进行文件的相关操作.我测试过的server版本是4.0.6. githu ...
- 04点睛Spring MVC 4.1-拦截器
转发地址:https://www.iteye.com/blog/wiselyman-2214292 4.1 拦截器 拦截器实现了对每一个请求处理之前和之后进行相关的处理,类似于Servlet的filt ...