【发布时间】:2011-09-28 21:54:17
【问题描述】:
我是 WCF 的新手。我习惯了 *.asmx 但它会被弃用,所以我决定深入研究 WCF。我想为我的服务提供一个简单的用户名 + 密码身份验证,但在网络上到处都是关于 X509 证书的。我想在 IIS 中托管我的服务,因此我将在其中启用 SSL。
我关注了一些关于 WCF 的 hello world 教程,但对所有新事物、datacontract、OperationContract、ServiceContract、所需接口、web.config 中的所有绑定、basicHttpBinding 等感到有些困惑。
我目前在File -> New project -> Visual C# -> WCF -> WCF Service Application
我有一个 hello world 应用程序,想知道保护它的最佳和最简单的方法是什么。我读过很多不同的东西,以至于我不知道什么是最适合我的情况。
托管在 IIS 中的服务将在互联网上可用(启用 ssl),并且我想将用户名和密码发送给几个受信任的人。
请为我提供最简单和合适的安全建议。
编辑
我正在尝试关注这篇博文:
http://codebetter.com/petervanooijen/2010/03/22/a-simple-wcf-service-with-username-password-authentication-the-things-they-don-t-tell-you/
但我无法发布元数据。我假设我的web.config 中有错误
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfServiceSimStars.MyServiceTypeBehaviors" name="FarmService.CustomerDeskOperations">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="RequestUserName" contract="WcfServiceSimStars.ISimService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="RequestUserName" >
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://mytestserver/simservice.svc" binding="WSHttpBinding"
bindingConfiguration="WSHttpBinding_ISimService" contract="WcfServiceSimStars.ISimService"
name="WSHttpBinding_ISimService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceSimStars.MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WcfServiceSimStars.UserValidatorr, WcfServiceSimStars" />
<serviceCertificate findValue="Farm" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
和我的解决方案浏览器:
编辑 2:
我尝试使用 Visual Studio 工具菜单中的 Microsoft Service Configuration Editor 打开我的 web.config 并收到此错误:
【问题讨论】:
-
如果你使用 ssl,你的 mexHttpBinding 需要是 mexHttpsBinding
-
我还没有在 IIS 中启用 SSL。想在没有 SSL 的情况下进行测试
-
好的,您在尝试发布元数据时遇到什么错误?
-
表示此服务的元数据发布已禁用
-
您的绑定称为 RequestUserName,但在您的端点中您引用的是 wshttpbinding_ISimService。端点中的绑定配置应与您提供的绑定名称匹配。
标签: wcf iis-7.5 wcf-binding wcf-security