如何整合WCF和ASP.NET之间的企业库验证应用程序块ValidationResults? [英] How to Integrate Enterprise Library Validation Application Block ValidationResults between WCF and ASP.NET?

查看:119
本文介绍了如何整合WCF和ASP.NET之间的企业库验证应用程序块ValidationResults?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

企业库验证应用程序块(VAB)与ASP.NET集成,并与WCF。

Enterprise Library Validation Application Block (VAB) integrates with ASP.NET and also with WCF.

有没有整合WCF与ASP.NET创建ValidationResults的方法吗?

Is there a way to integrate ValidationResults created in WCF with ASP.NET?

例如。 ASP.NET网页调用WCF服务。 WCF服务使用验证VAB的数据,并通过FaultContract返回验证信息。 ASP.NET页面可以利用的结果,并显示一些错误信息。然而,一个普通的方法是,以指示哪些字段具有错误(例如直列消息或星号)。似乎大多数这些方法将涉及能够验证结果与控制或与验证相关。

e.g. an ASP.NET web page invokes a WCF service. The WCF service validates the data using VAB and returns validation information via a FaultContract. The ASP.NET page can take the results and display some error messages. However, a common approach is to indicate which fields have errors (e.g. inline message or asterisk). It seems that most of these approaches will involve being able to correlate the validation result with a control or with a validator.

我不认为有一个开箱即用的解决方案,但也好奇,如果有人这样做,什么他们的做法是。

I don't think there is an out of the box solution but was also curious if anyone had done this and what their approach was.

推荐答案

由于没有开箱即用解决方案中都没有发布任何答案,我会分享我实现。我不爱的方法,但它是为我工作。

Since there is no out of the box solution and there aren't any answers posted, I will share what I implemented. I'm not in love with the approach but it is working for me.

概述

其基本做法是,ASP.NET页面来填充的DataContract对象正在验证控件的ClientID的特性之间的映射。当发生验证错误时,返回客户端Id从服务到asp.net页面回为一个FaultContract的一部分。然后,从FaultException异常细节提取; ASP.NET页面检索导致错误和适当可以采取行动(例如变更控制的外观和感觉或设置一个验证文本)控制的客户端Id。

The basic approach is for the ASP.NET page to populate a mapping between properties on the DataContract objects to the ClientId of the control that is being validated. When a validation error occurs the ClientId is returned back from the service to the asp.net page as part of a FaultContract. Then the details from the FaultException are extracted; the ASP.NET page retrieves the ClientId of the control that caused the error and appropriate action can be taken (e.g. change control look and feel or set the text on a validator).

详细信息

所有DataContract对象从暴露字典的基类继承。这本词典是用于对象属性映射到ASP.NET控件。在词典中,关键是DataContract对象的属性名和值是控制的客户端Id。调用服务之前,客户端必须重视字典的DataContract对象。

All of the DataContract objects inherit from a base class that exposes a Dictionary. This dictionary is used to map object properties to ASP.NET controls. In the Dictionary, the key is the property name on the DataContract object and the value is the ClientId of the control. Before invoking a service, the client must attach the Dictionary to the DataContract object.

在为ValidationResult是由企业库创建它包含了一个名为Target属性是被验证的对象。为ValidationResult还包含一个属性称为关键是从已验证的目标对象中的属性的名称。在为ValidationResult关键也是一个关键成是在ASP.NET页面调用服务之前设置词典。

When a ValidationResult is created by Enterprise Library it contains a property called Target which is the object that was validated. ValidationResult also contains a property called key which is the name of the property from the target object that was validated. The ValidationResult key is also a key into the Dictionary that was set in the ASP.NET page before calling the service.

使用的为ValidationResult键时,ASP.NET提供的信息(客户端Id)可以从以下的ValidationResult目标提取。然后将信息添加为的ValidationResult的标签。不幸的是,标签是只读属性,因此它必须通过创建一个新的ValidationResult并通过标记的构造函数中设置。

With the ValidationResult key, the ASP.NET supplied information (ClientId) can be extracted from the ValidationResult Target. The information is then added as the Tag of the ValidationResult. Unfortunately, Tag is a readonly property so it has to be set by creating a new ValidationResult and passing the tag to the constructor.

ValidationResults的集合,然后转化为pre-现有CustomValidationResults集合(这看起来就像为ValidationResult),我们需要使用。然后CustomValidationResults被添加到自定义ValidationFault和FaultException异常被抛出。

The collection of ValidationResults is then transformed to a pre-existing CustomValidationResults collection (which looks just like ValidationResult) that we needed to use. The CustomValidationResults are then added to a custom ValidationFault and a FaultException is thrown.

该ValidationFaults从F​​aultException异常在ASP.NET页面然后提取。该ValidationFault包含与错误相关联,这样的页面可以选择其认为合适显示的邮件控制的客户端Id。

The ValidationFaults are then extracted from the FaultException in the ASP.NET page. The ValidationFault contains the ClientId of the control which is associated with the error so the page can choose to display the Messages as it sees fit.

这篇关于如何整合WCF和ASP.NET之间的企业库验证应用程序块ValidationResults?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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