WCF中的参数检查器 [英] Parameter inspectors in WCF

查看:49
本文介绍了WCF中的参数检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查WCF提供的检查员.

I was going through the inspectors WCF provides.

一种方法是实现IParamterInspector,该工具基本上用于WCF管道中的传入参数验证.

One is to implement IParamterInspector which is used basically for incoming parameter validation in the WCF pipeline.

我理解只有这样一点,才能将验证与实现分开.

I understand only one point like this will lead to separation of validation from implementation.

但是似乎并不令人印象深刻,因为我们仍然可以将验证代码放在指定为数据成员的属性中,我认为更易于在粒度级别进行管理.

But it does not seem to be that impressive as we can anyway put validation code in properties specified as data member which i feel like is easier to manage at the granular level.

是否有任何强制使用IParameterInspector而不是在属性中使用验证的实时方案.

is there any live scenario which compels to use IParameterInspector instead of using validation in properties.

此致

推荐答案

在某些情况下您无法进行验证在数据合同的属性之内.例如,如果要确保输入的值不为null;如果参数类型不是类,并且您想在其上添加一些验证 (例如,整数值在一定范围内,字符串值与某个正则表达式匹配,等等),如果您需要在多个参数之间进行交叉验证(例如,如果一个参数设置了属性X,则其他参数不能具有属性 Y set等).

There are some scenarios where you can't do validation within the properties of the data contract. For example, if you want to ensure that the value of the input is not null; if the parameter type is not a class and you want to add some validation over it (e.g., an integer value is within a range, a string value matches a certain regular expression, etc), if you need to do cross-validation between multiple parameters (e.g., if one parameter has a property X set, then the other parameter cannot have property Y set, etc), among others.

此外,除了验证外,您还可以在IParameterInspector中执行其他操作.您可以轻松地进行日志记录(最常见的情况).您可以在到达该点之前修改传递给该操作的传入参数(可能 在完成一些预验证后).您还可以根据输入值在调用的输出上运行一些相关逻辑(通过在BeforeCall中返回一些非空值).

Also, there are other actions you can do within the IParameterInspector, besides validation. You can easily do logging (the most common scenario). You can modify the incoming parameters passed to the operation prior to reaching that point (possibly after some pre-validation has been done). You can also do run some correlation logic on the output of the call based on input values (by returning some non-null value in BeforeCall).


这篇关于WCF中的参数检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆