简体   繁体   English

WCF:抑制FaultExceptions和ObjectDataSource绑定

[英]WCF: Supressing FaultExceptions & ObjectDataSource Binding

I had designed a web service which, upon each method call, would return a structure of some type T if the request were successfully conducted, or otherwise throw a FaultException to the client to signal some error. 我设计了一个Web服务 ,如果成功执行了请求,则在每次方法调用时将返回某种T类型的结构,否则,将FaultException抛出给客户端以发出一些错误信号。 One of the client applications was an ASP.NET application with a bunch of ObjectDataSource objects directly tied to the methods of the service. 客户端应用程序之一是ASP.NET应用程序,该应用程序具有一堆直接与服务方法绑定的ObjectDataSource对象。 Those objects would take care of things such as GridView paging or DropDown populating for themselves. 这些对象将自己处理诸如GridView分页或DropDown之类的事情。

Unfortunately, I was just now ordered to remove all FaultException from the service and wrap the types I was returning into a generic ServiceResponse<T> structure which wraps the original return structure of type T and adds some more fields to transmit exception information. 不幸的是,我现在被命令从服务中删除所有FaultException ,并将返回的类型包装到通用的ServiceResponse<T>结构中,该结构包装了类型T的原始返回结构并添加了更多字段以传输异常信息。 Having no other choice, I did this right away and replaced all the old service proxy calls with a call to a generic ExecuteMethod<TChannel, TReturn> method which takes care for itself of unwrapping the value if the request was successful or throw some exception otherwise. 别无选择,我立即执行了此操作,并用对通用ExecuteMethod<TChannel, TReturn>方法的调用替换了所有旧的服务代理调用,该方法自己负责在请求成功后解包值,否则抛出一些异常。 The problem now is that, since this new method is generic, I can't tie an ObjectDataSource to it, and GridView automatic paging is gone. 现在的问题是,由于此新方法是通用的,因此我无法将ObjectDataSource绑定到它,并且GridView自动分页不见了。

Since ObjectDataSource doesn't support generic methods, nor it supports generic classes without a lot of mangling with assembly-qualified types names which I would like to avoid, I am left with the options of either page the GridView manually, which I would like to avoid as well, or writing a proxy to wrap every necessary service call and return the desired value, which then is "wrapping a wrapper". 由于ObjectDataSource不支持泛型方法,也不支持泛型类,而没有很多我想避免的程序集限定类型名称的困扰,因此我只能手动选择任一页面GridView的选项。也要避免,或者编写代理以包装每个必要的服务调用并返回所需的值,然后将其“包装包装器”。 Can you please help me decide which one will not be the worst? 您能帮我决定哪一个不会最差吗? Do I have any other options in this case? 在这种情况下,我还有其他选择吗?

I prefer the "wrapping a wrapper" approach as you call it. 我喜欢您所说的“包装包装纸”方法。 Architecturally it's entirely valid since each has a single responsibility. 从结构上讲,这是完全有效的,因为每个人都有一个责任。

It will be a pain to maintain if the service contract is not stable but it's probably more maintainable than the assembly qualified name approach will be in the same circumstances. 如果服务合同不稳定,那么维护起来会很痛苦,但是在相同情况下,它可能比程序集合格名称方法更容易维护。

(RANT: As an aside I trust the person who "ordered" you to remove the Faults from the service understands the impacts this will have on interoperability of the service. Also, the approach allows the service implementors and consumers to get themselves into difficulty if they fail to properly implement your new proprietary protocol. It seems like it doesn't actually achieve anything anyway since all you're changing is the mechanism by which a Fault gets converted to an Exception at the client.) (RANT:顺便说一句,我相信“命令”您从服务中删除错误的人理解这将对服务的互操作性产生影响。此外,该方法还允许服务实现者和使用者在遇到困难时陷入困境。它们无法正确实现您的新专有协议。由于您所更改的只是在客户端将Fault转换为Exception的机制,因此它似乎并没有真正实现任何目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM