2010-09-28 33 views
1

这里的想法是,对于我的测试,在我承诺购买SSL证书之前,我想以非SSL模式启用WCF服务。我在过去使用这段代码完成了它,但在我的生活中,无法弄清楚如何将它转换成web.config文件。在WCF中启用不使用SSL的基本HttpBinding

如果有人能让我在正确的方向上了解如何去做这个翻译,那将是非常感谢。

   Binding basicBinding = null; 
       if (RegistryConnectionStringFactory.UseSslForCommunications) 
       { 
        basicBinding = new BasicHttpBinding(); 
        (basicBinding as BasicHttpBinding).Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; 
        (basicBinding as BasicHttpBinding).Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 

        creds.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.MembershipProvider; 
        creds.UserNameAuthentication.MembershipProvider = Membership.Provider; 
       } 
       else 
       { 
        HttpTransportBindingElement transport = new HttpTransportBindingElement() 
        { 
         AuthenticationScheme = System.Net.AuthenticationSchemes.Basic 
        }; 
        basicBinding = new CustomBinding(transport); 

        svcHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new AspNetUsernamePasswordValidator(); 
        svcHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; 
       } 

回答

1

因为你的帖子建议,要做到这一点,以避免购买SSL证书,然后再测试compl ete,我想问:为了节省一些时间,您可以使用makecert创建自己的自签名证书吗?

如果是这样,这些说明可能会有所帮助。

要创建根证书密钥文件...

makecert -r -pe -n "CN=My Own Authority,O=My Company,C=US" -ss CA -sr CurrentUser -a sha1 -sky signature -sv mycert.pvk mycert.cer 

要创建一个.PFX文件...

makecert -pe -n "CN=localhost" -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -ic mycert.cer -iv mycert.pvk -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -sv localhost.pvk localhost.cer 
pvk2pfx -pvk localhost.pvk -spc localhost.cer -pfx localhost.pfx 

然后,使用证书管理单元,导入mycert.cer文件导入本地计算机上的受信任根证书颁发机构将告知在本地计算机上运行的应用程序,由您自己的权限签署的任何证书都是可信任的。

接下来,您将localhost.pfx文件导入本地计算机上的个人存储。 (这样做使得证书可供IIS使用,以便它可以通过您自己的权限声明自己是名为“localhost”的服务器。)

有关于如何将.PFX文件导入IIS 7的详细描述这里:http://www.digicert.com/ssl-support/pfx-import-export-iis-7.htm

+0

我做了一些进一步的调查,发现像Verisign这样的公司允许您下载测试SSL证书。 http://www.verisign.com/ssl/buy-ssl-certificates/free-ssl-certificate-trial/我曾考虑过这个问题,但是想避免头痛。我认为做这样的事情可能是最好的选择。 – 2010-09-29 06:42:10

+0

P.S.我接受你的答案,部分原因是因为它接近我要做的事情,部分原因是社区的其他成员停止殴打我,因为不接受没有正确或错误答案的问题的答案。 – 2010-09-29 06:43:32

+0

我在这里有点太新,以至于完全理解接受答案的重要性,但是我感谢你。无论如何,我希望你能够得到你想要的结果。 – 2010-09-29 13:41:47

0

我今天在看类似的东西,但我的知识并非100%完整。

对于绑定,你需要做这样的事情:

<bindings> 
    <customBinding> 
    <binding name="CustomBinding"> 
     <httpTransport authenticationScheme="Basic"/> 
    </binding> 
    </customBinding> 

然后,你需要创建自定义的验证一个serviceBehaviour:

 <behavior name="serviceBehavior" > 
     <serviceAuthorization principalPermissionMode="UseAspNetRoles"roleProviderName="CustomRolesProvider" /> 
     <serviceCredentials> 
     <userNameAuthentication customUserNamePasswordValidatorType ="AspNetUsernamePasswordValidator [Fully qualified name]" userNamePasswordValidationMode="Custom" /> 
     </serviceCredentials> 

显然不是测试,但类似的配置只是为我工作,它可能让你开始...

+0

交通运输凭证。当我做到这一点,似乎有打破了我的能力,登录到该网站。 – 2010-09-29 06:41:11

2

基于配置的BasicHttpBinding方法有什么问题?您只需使用TransportWithMessageCredential和UserName凭据通过HTTPS进行通信,或使用TransportCredentialOnly和Basic凭证进行HTTP通信。

+0

看起来好像当我走了那条路线时,它破坏了应用程序本身的基于表单的身份验证。 – 2010-09-29 06:40:14

1

这是一个极端,但您可以通过将安全模式设置为“无”来允许匿名非SSL。匿名也可能会影响您的测试,因此可能不推荐。

<binding name="HttpBasicSecurityConfig"> 
    <security mode="None"> 
    </security> 
</binding> 

http://msdn.microsoft.com/en-us/library/ms731172.aspx

在绑定

Type Description 
None Specifies that the client does not need to present any credential. This translates to an anonymous client. 
+0

这将是伟大的东西像Twitter的API,但这需要有用户登录。不幸的是,由于缺乏资金,我不得不收拾这个项目。 – 2011-10-12 21:06:00