WCF REST和自定义错误处理程序 [英] WCF REST and Custom Error Handler

查看:103
本文介绍了WCF REST和自定义错误处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RESTful WCF服务,并且我试图推出一个扩展WebHttpBehavior的自定义行为,以便为我的服务提供一个自定义错误处理程序(当然是通过实现IErrorHandler来实现).当我调试服务时,我遇到的唯一断点是BehaviorExtensionElement的BehaviorType属性上的吸气剂.其他任何方法都不会被调用. BehaviorExtensionElement.CreateBehavior(),WebHttpBehavior.AddServerErrorHandlers()以及我实现IErrorHandler时一无所获.这使我相信没有向WCF注册任何东西.我的服务在app.config中定义.当我逐步调用服务的一项操作时,我希望引发异常的过程将迫使我的服务将工作转移到我的错误处理程序中.但是事实并非如此……我的服务停止并抛出未处理的异常,结果没有任何内容发送给客户端.难道我做错了什么?我不了解这个过程吗?如果有人可以帮助我,将不胜感激!

我的代码基本上具有IErrorHandler的实现,以及使用AddServerErrorHandlers()的重写派生WebHttpBehavior的类,以及具有对BehaviorTypeType和方法CreateBehavior().没什么好看的,但是我有种感觉,我可能会缺少一些东西...

这是我的app.config:

<? 版本 "1.0" 编码 " utf-8"; < 配置 > "color:blue">< system.serviceModel > 服务 .服务 名称 = " CachingService" ; 行为配置 = & quot; CachingServiceBehavior' > < 端点 地址 = " ="color:red">行为配置 = " WebBehavior" red> binding " webHttpBinding" 合约 " CachingFramework.ICachingService" > </ 端点 > </ 服务 > "color:blue"></ 服务 > 扩展名 . behaviorExtensions > < 添加 名称 = &; faultingWebHttpBehavior"" 类型 = " CachingFramework.FaultingWebHttpBehaviorElement,CachingFramework,Version = 1.0.0.0,Culture = neutral, PublicKeyToken = ..." /> </ behaviorExtensions > </ > :blue>< > endpointBehaviors > < 行为 > 名称 = " WebBehavior" > < faultingWebHttpBehavior /> </ 行为 > </ > 行为 > syst em.serviceModel > </ 配置 >

解决方案

没人吗?一点想法都没有吗?认真吗?...

第百万次调试我的服务时,似乎像对FaultingWebHttpBehaviorElement一样,当我将 WebHttpBehavior 子类化时,我在 ApplyDispatchBehavior AddServerErrorHandlers ,任何断点都不会被击中...那么为什么没有调用任何东西呢???它似乎像基本的 WebHttpBehavior 类,而不是我的自定义类.另一个类是派生 BehaviorExtensionElement 的类,它在 CreateBehavior 上设置了一个断点,并为 BehaviorType 设置了getter. BehaviorType getter的断点被命中,而CreateBehavior方法从不被命中.这是怎么回事!!!?!?????????????

I have a RESTful WCF service, and I am trying to roll a custom behavior that extends the WebHttpBehavior, to provide my service a custom error handler (by implementing IErrorHandler of course). When I debug my service, the only breakpoint I hit is the getter on the BehaviorExtensionElement's BehaviorType property. None of the other methods are ever invoked; BehaviorExtensionElement.CreateBehavior(), WebHttpBehavior.AddServerErrorHandlers(), as well as nothing in my implementation of IErrorHandler. This leads me to believe that something isn't being registered with WCF. My service is defined in the app.config. When I step-through a call to one of my service's operations, I would expect that the process of throwing an exception would force my service to transfer the work to my error handler. But this is not the case... My service stops and throws me an unhandled exception, and nothing is sent to the client as a result. Am I doing something wrong? Am I not understanding this process? If someone could help me out it would be greatly appreciated!

My code basically has implementations of IErrorHandler, and classes that derive WebHttpBehavior with an override on AddServerErrorHandlers(), and also BehaviorExtensionElement with an override for the property BehaviorType and method CreateBehavior(). Nothing fancy, but I have a feeling I may be missing something...

This is my app.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
        <services> 
            <service name="CachingService" behaviorConfiguration="CachingServiceBehavior"
                <endpoint address=""  
                          behaviorConfiguration="WebBehavior" 
                          binding="webHttpBinding" 
                          contract="CachingFramework.ICachingService"></endpoint> 
            </service> 
        </services> 
        <extensions> 
            <behaviorExtensions> 
                <add name="faultingWebHttpBehavior" type="CachingFramework.FaultingWebHttpBehaviorElement, CachingFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=..."/> 
            </behaviorExtensions> 
        </extensions> 
        <behaviors> 
            <endpointBehaviors> 
                <behavior name="WebBehavior"
                    <faultingWebHttpBehavior/> 
                </behavior> 
            </endpointBehaviors> 
        </behaviors> 
    </system.serviceModel> 
</configuration> 

解决方案

No one? No ideas at all? Seriously?...

Debugging through my service again for the millionith time, it appears that when I subclassed WebHttpBehavior, as I do with FaultingWebHttpBehaviorElement, and I place breakpoints on ApplyDispatchBehavior and AddServerErrorHandlers, none of the breakpoints are ever hit... So why is nothing being invoked??? It seems to be acting like the base WebHttpBehavior class and not my custom class. The other class, the class that derives BehaviorExtensionElement, has a breakpoint set on CreateBehavior and the getter for BehaviorType. The breakpoint for BehaviorType getter is hit, while the CreateBehavior method is never hit. What is going on!!!!?!??!??!!!??!????!??


这篇关于WCF REST和自定义错误处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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