为无效的用户名/密码投掷XML Web服务异常 [英] Throwing a XML Web Service Exception for invalid username / password

查看:155
本文介绍了为无效的用户名/密码投掷XML Web服务异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Web服务,并且使用了一个Soap头来进行身份验证,如下所述:
http ://aspalliance.com/805

I've created a web service and am using a Soap header for authentication, as described here: http://aspalliance.com/805

我已经调整了它,所以在每个方法中,它调用一个单独的验证方法,其中搜索db中的用户名和密码,并返回true或false。
我的问题是,在这个方法中,如果它返回false(即,用户未被验证)我应该如何抛出一个异常,过滤回消费者应用程序?

I've adapted it, so that in every method, it calls a seperate "authenticate" method, which searches username and password in the db, and returns true or false. My question is, within this method, if it returns false (ie, the user isn't validated) how should i throw an exception, that filters back to the consumer application?

推荐答案

我已经使用了soap异常登录失败:

i have used soap exceptions for login fails:

[WebMethod]
    [SoapHeader("authentication")]
    public User Authenticate()
    {
        try
        {
            authentication.Roles = new string[] { UserRoles.Users };
            ConfigureAuthentication();
            Service<ISecurity>.Interface.Authenticate();
            Guid userId = Service<ISecurity>.Interface.GetUserId(authentication.UserName);
            return Service<IObjectRetriever>.Interface.Retrieve<User>(userId);
        }
        catch (Exception ex)
        {
            WriteException(ex);
            throw new SoapException(ex.Message, new XmlQualifiedName(SoapException.ServerFaultCode.Name), ex);
        }
    }

这篇关于为无效的用户名/密码投掷XML Web服务异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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