我试图在我的wcf配置中找到错误,但我无法找到问题所在。我需要更多的眼睛;无论如何,我想在wcf中使用自定义认证验证。我在我的CertificateValidator类中设置了断点,但是这个断点并没有捕获任何请求,但是应用程序正在运行,我可以发送请求(没有证书)。
这是我的配置
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="104857600">
<security>
<message clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="AccountService" behaviorConfiguration="">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="IAccountService"></endpoint>
</service>
<service name="PortalService" behaviorConfiguration="">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="IPortalService"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="Custom" customCertificateValidatorType="Services.Validators.CertificateValidator, Services" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
答案 0 :(得分:0)
您使用的是NET 4还是4.5?
我认为你错过的事情:
basicHttpBinding
需要使用<security mode="Message">
(目前您没有指定它,这意味着默认为"None"
)basicHttpBinding
需要name=
,因此可以引用basicHttpBinding
bindingConfiguration=
name=
,因此可以引用behaviorConfiguration=
<serviceCertificate>
中指定<serviceCredentials>
,该协议用于与客户建立安全通道'<serviceCertificate>'
中的<clientCredentials>
,以便它可以与服务器建立安全通道<clientCertificate>
中指定<clientCredentials>
或以编程方式) 注意:您应该至少创建了2个证书 - 1用于服务器的标识 - 客户使用1个或多个凭证(取决于您是否决定所有客户应出示相同的证书,或者如果您为每个客户分配唯一的证书) - 请勿使用相同的证书进行服务器识别和客户端凭证
一些帮助理解“消息级安全性”的链接:
如果您的邮件交换速度太慢,请考虑使用“传输”级安全性。
试试这个:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="securebasicHttpBinding" maxReceivedMessageSize="104857600">
<security mode="Message">
<message clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="secureBehaviour" name="AccountService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="securebasicHttpBinding"
contract="IAccountService" />
</service>
<service behaviorConfiguration="secureBehaviour" name="PortalService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="securebasicHttpBinding"
contract="IPortalService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="secureBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<serviceCertificate ...something goes here... />
<clientCertificate>
<authentication certificateValidationMode="Custom" customCertificateValidatorType="Services.Validators.CertificateValidator, Services" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>