一种方法列表如下。
为了举办您可能需要您的Web服务器上运行以下命令WCF服务:
"%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r –y
在IIS设置您的网站使用https绑定(只),并在SSL设置您将其设置为需要SSL并需要客户端证书。
仅此一项仅允许使用有效的客户端证书和Web服务器信任的颁发者访问您的服务(和wsdl)。
为了限制访问你可以设置你的WCF的配置文件与bindingConfiguration具体证书:
<basicHttpBinding>
<binding name="MyBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
而且具有自定义证书验证作为behaviorConfiguration:
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="Custom"
customCertificateValidatorType="<project-namespace>.ClientCertificateValidator, <project-namespace>"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
最后一点将项目中的新类自定义验证器实现为:
public class ClientCertificateValidator : X509CertificateValidator
{
public override void Validate(X509Certificate2 certificate)
{
if (certificate.Thumbprint != <allowed-thumbprint>)
throw new Exception();
}
}
来源
2011-07-28 06:38:03
lox