转 使用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里边,如果参数不正确就返回相应的错误码.如果接口数 ...
随机推荐
- mysql 安装参考
https://blog.csdn.net/qq_38756992/article/details/84929787 https://www.cnblogs.com/joyny/p/10991194. ...
- 从0开始学爬虫7之BeautifulSoup模块的简单介绍
参考文档: https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ # 安装 beautifulsoup4 (pytools) D:\pyt ...
- ISO/IEC 9899:2011 条款6.5——表达式
6.5 表达式 1.一个表达式是操作符与操作数的一个序列,这些操作符与操作数指定了一个值的计算,或指派一个对象或一个函数,或是生成副作用,或执行上述操作的组合.对一个操作符的操作数的值计算顺序排在对该 ...
- 【转】asp获取【微信公众平台】Access Token的源代码下载
在做微信开发时候,经常要用到Access Token,但是官网提供的都是基于php写的,我用asp写了,有需要可以直接复制去用,模板消息,jdk上传图片,客服消息等全需要这个:'获取 access_t ...
- VPB编译日志1
1>------ 已启动全部重新生成: 项目: ZERO_CHECK, 配置: Release x64 ------1> Checking Build System1> CMake ...
- get请求utf-8解码
package utils;import java.io.UnsupportedEncodingException;import java.net.URLDecoder; /*** <p> ...
- easyui前台改变datagrid某单元格的值
有时候前台完成某个操作后要修改datagrid的值, 也许这个datagrid是没有保存的, 所以要修改后才能传递到后台; 也许要其他操作过后才需请求后台; 这些情况都需要前台对datagrid的单元 ...
- 【Leetcode_easy】1046. Last Stone Weight
problem 1046. Last Stone Weight 参考 1. Leetcode_easy_1046. Last Stone Weight; 完
- LM_ReadImgMode.js PC单页轮播读图模式组件,零依赖!
LM_ReadImgMode.js PC单页轮播读图模式组件,零依赖! github:http://dtdxrk.github.io/LM-ReadImgMode/ TXT 1.全新的2.0版本,脱离 ...
- 【VS开发】IP地址格式转换(htonl、ntohl;inet_addr、inet_ntoa)
1.htonl ()和ntohl( ) u_long PASCAL FAR ntohl (u_long netlong); u_short PASCAL FAR ntohs (u_short nets ...