简体   繁体   English

如何处理SilverLight 4和WPF应用程序的WCF身份验证

[英]How-To Deal with WCF Authentication for Both SilverLight 4 and WPF Application

I'm looking for advice in order to deal with WCF Authentication for an application targetting both SilverLight and WPF client interface. 我正在寻找建议,以便为针对SilverLight和WPF客户端接口的应用程序处理WCF身份验证。

EDIT : Actually, the authentication mode i need is Username/Password combinaison. 编辑:实际上,我需要的身份验证模式是用户名/密码组合。

In addition, in the future the application should be able to work in full-standalone mode (both client (WPF) and server on the same computer within the same application). 此外,将来应用程序应该能够以完全独立模式(同一应用程序内的同一台计算机上的客户端(WPF)和服务器)工作。 So should i don't use WCF in that case ? 那么在这种情况下我不应该使用WCF吗?

EDIT : Another addition, in the future again the application should be able to work in local network client-server mode (but without IIS), like a game. 编辑:另外一个补充,在未来再次应用程序应该能够在本地网络客户端 - 服务器模式(但没有IIS),如游戏。 So should i don't use WCF in that case to ? 那么在这种情况下我不应该使用WCF吗? Or any other option ? 还是其他选择?

You can implement your own validator by inheriting from the UserNamePasswordValidator and setting the customUserNamePasswordValidatorType in your behavior configuration like this: 您可以通过继承UserNamePasswordValidator并在行为配置中设置customUserNamePasswordValidatorType来实现自己的验证器,如下所示:

<behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom"
                                                customUserNamePasswordValidatorType="MyNamespace.MyValidator, MyNamespace" />
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>
        </behaviors>

On the client side you can set the username/password combination into the ClientCredentials.UserName.UserName/Password property of your service. 在客户端,您可以将用户名/密码组合设置为服务的ClientCredentials.UserName.UserName / Password属性。

Check out this solution, using an AuthenticationService. 使用AuthenticationService查看此解决方案。 I like it and decided to use it for a tri-platform application (web/SL/WPF) 我喜欢它并决定将它用于三平台应用程序(web / SL / WPF)

http://msdn.microsoft.com/en-us/library/system.web.applicationservices.authenticationservice.aspx http://msdn.microsoft.com/en-us/library/system.web.applicationservices.authenticationservice.aspx

Follow the links for sample implementations. 按照示例实现的链接进行操作。

In this manner, you can rely on a classic custom ASP .NET MembershipProvider implementation (even in a standalone client). 通过这种方式,您可以依赖经典的自定义ASP .NET MembershipProvider实现(即使在独立客户端中)。

IIS is not a requirement for hosting WCF service. IIS不是托管WCF服务的要求。 Take a look at this link for various hosting options. 请查看此链接以了解各种主机选项。 Also WCF allows communication over various protocols. 此外,WCF允许通过各种协议进行通信。 Take a look at this link for a summary of hosting options based on operating platform and communication protocol. 请查看此链接,了解基于操作平台和通信协议的托管选项摘要。

There are few techniques that can be used for authentication of WCF services (X509 certificates , token , username/password and windows authentication. Selecting the correct credential type is important. 可用于验证WCF服务的技术很少(X509证书,令牌,用户名/密码和Windows身份验证。 选择正确的凭据类型很重要。

Assuming (since you are using silverlight & WPF) that the setup is within a windows environment you can use windows authentication. 假设(因为您使用的是Silverlight和WPF)设置在Windows环境中,您可以使用Windows身份验证。 To enable windows authentication follow the steps highlighted and host your service on IIS. 启用Windows身份验证,请按照突出显示的步骤在IIS上托管服务。

Hope this helps and good luck!. 希望这有帮助,祝你好运!

The advantage of using WCF is that if you want to expose a service within the network or to the outside world you can just change/add some additional configurations without any change to the code. 使用WCF的优点是,如果要在网络中或外部公开服务,您只需更改/添加一些其他配置,而无需对代码进行任何更改。

So in your scenario of having both client and server on one machine or within a network is absolutely fine and the easy way is to have 2 end points exposed that deals with your requirements on the same service. 因此,在您的情况下,在一台计算机上或在网络中同时拥有客户端和服务器是绝对正确的,并且简单的方法是暴露2个端点,以处理您对同一服务的要求。

You can get around with one endpoint as well but using different endpoints with different binding mechanism reduces your overhead during authentication. 您也可以使用一个端点,但使用具有不同绑定机制的不同端点可以减少身份验证期间的开销。 Ex: When you are on the same machine you can use a net:pipe or net:tcp binding When you are within the domain you can use net:tcp or httpbinding. 例如:当你在同一台机器上时,你可以使用net:pipe或net:tcp binding当你在域内时,可以使用net:tcp或httpbinding。

Performance differs when using different bindings. 使用不同的绑定时性能不同。

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

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