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操作行为的更多相关文章

  1. golang 防SQL注入 基于反射、TAG标记实现的不定参数检查器

    收到一个任务,所有http的handler要对入参检查,防止SQL注入.刚开始笨笨的,打算为所有的结构体写一个方法,后来统计了下,要写几十上百,随着业务增加,以后还会重复这个无脑力的机械劳作.想想就l ...

  2. 自研后端HTTP请求参数验证器服务ParamertValidateService

    好处:方便了后端对HTTP请求中参数进行核验,只需一次编写效验器,一行代码便可对所有参数的pojo进行参数核验!而且更改效验逻辑时只需要更改效验器类即可,实现了解耦合. 只需要程序员按照规范开发一个P ...

  3. 实现自定义的参数解析器——HandlerMethodArgumentResolver

    1.为什么需要自己实现参数解析器 我们都知道在有注解的接口方法中加上@RequestBody等注解,springMVC会自动的将消息体等地方的里面参数解析映射到请求的方法参数中. 如果我们想要的信息不 ...

  4. SpringMVC 自定义参数解析器.

    一.简述 有没有想过像 @RequestParam.@RequestBody 这些注解的工作原理呢?为什么 form 表单.application/json 的参数能够直接封装进 Bean 对象中呢? ...

  5. 一步一步自定义SpringMVC参数解析器

    随心所欲,自定义参数解析器绑定数据. 题图:from Zoommy 干货 SpringMVC解析器用于解析request请求参数并绑定数据到Controller的入参上. 自定义一个参数解析器需要实现 ...

  6. python 拼写检查代码(怎样写一个拼写检查器)

    原文:http://norvig.com/spell-correct.html 翻译:http://blog.youxu.info/spell-correct.html 怎样写一个拼写检查器 Pete ...

  7. SpringMVC自动封装List对象 —— 自定义参数解析器

    前台传递的参数为集合对象时,后台Controller希望用一个List集合接收数据. 原生SpringMVC是不支持,Controller参数定义为List类型时,接收参数会报如下错误: org.sp ...

  8. 如何写一个拼写检查器-by Peter Norvig

    本文原著:Peter Norvig  中文翻译:徐宥 上个星期, 我的两个朋友 Dean 和 Bill 分别告诉我说他们对 Google 的快速高质量的拼写检查工具感到惊奇. 比如说在搜索的时候键入 ...

  9. 实现一个可配置的java web 参数验证器

    当使用java web的servlet来做接口的时候,如果严格一点,经常会对请求参数做一些验证并返回错误码.我发现通常参数验证的代码就在servlet里边,如果参数不正确就返回相应的错误码.如果接口数 ...

随机推荐

  1. Flutter -------- Http库实现网络请求

    第三方库 http实现网络请求,包含get,post http库文档:https://pub.dev/packages/http 1.添加依赖 dependencies: http: ^0.12.0 ...

  2. Kotlin数据类型 Unit、Nothing与Nothing?、Any与Any?

    Kotlin数据类型 Unit.Nothing与Nothing?.Any与Any?   本文链接:https://blog.csdn.net/ldxlz224/article/details/9440 ...

  3. Qt编写气体安全管理系统15-网络转发

    一.前言 在本系统中网络转发是个什么功能含义呢,其实就是将本地采集设备的所有数据打包发送到指定的网络地址,默认采用UDP的形式,无连接开销小,我也是看到很多的组态软件有这个功能,其实现有的很多的气体探 ...

  4. 转 Java连接Oracle数据库的简单示例

    https://www.cnblogs.com/joyny/p/11176643.html https://community.oracle.com/thread/4096458 import jav ...

  5. maven 引入的jar有出现两种图标

    两种同样都引入到maven项目中,但是第二种在打包的过程中会显示找不到jar,无法调用!

  6. django 自定义 密码加密方式 及自定义验证方式

    在django1.6中,默认的加密方式是pbkdf_sha256,具体算法不表,一直以来用django的自带用户验证都十分顺手,但如果需要修改默认加密方式为md5,具体方法为: 在settings.p ...

  7. IE6利用iframe遮挡 弹层 select

    ie6的老bug了,select老是会挡住 弹层里的内容. 解决办法:(box需要设置高度) <div class="box"> <!--[if IE 6]> ...

  8. CF1266C Diverse Matrix

    思路:构造题. 实现: #include <bits/stdc++.h> using namespace std; ][]; int main() { int r, c; while (c ...

  9. WXSS选择器

  10. console.log()和alert()的区别

    一直都是知道console.log()和alert()是有区别的,但是具体有什么区别就不清楚了,后来在权威指南里注意到了说alert()具有侵入性才来查一查两者的具体区别. 查询到的区别: alert ...