HTTP请求被拒绝,客户端认证方案为“匿名”。

8
这似乎是一个普遍的问题,我查看了所有这里的答案,但没有一个有所帮助。
我正在尝试让SSL与basichttpbinding和托管在IIS上的WCF服务一起工作。我认为问题出在IIS或证书方面。我已在IIS管理器中创建了一个自签名证书。我的证书名为“mycomputer”,并已放置在受信任的根证书下。客户端没有找到证书的问题。
我的IIS设置是启用匿名身份验证,并禁用其他所有内容。还需要SSL并接受客户端证书。这是正确的吗?如果我选择忽略,会出现错误。
我无法看出我的配置有什么问题,这些是否正确?
服务配置:
<system.serviceModel>
<services> 
  <service behaviorConfiguration="MyBehaviour" name="BasicHttpSecTest.Service1"> 
    <endpoint name="MyEndPoint" address="https://mycomputer/wp/" binding="basicHttpBinding" bindingConfiguration="ClientCertificateTransportSecurity" contract="BasicHttpSecTest.IService1" /> 
    <!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />-->
  </service> 
</services> 
<behaviors> 
  <serviceBehaviors> 
    <behavior name="MyBehaviour"> 
      <serviceMetadata httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceCredentials>
        <clientCertificate>
          <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
        </clientCertificate>
      </serviceCredentials>
    </behavior> 
  </serviceBehaviors> 
</behaviors> 
<bindings> 
  <basicHttpBinding> 
    <binding name="ClientCertificateTransportSecurity"> 
      <security mode="Transport"> 
        <transport clientCredentialType="Certificate" />
      </security> 
    </binding> 
  </basicHttpBinding> 
</bindings>
</system.serviceModel> 

客户端配置:

<system.serviceModel> 
<client>
    <endpoint address="https://mycomputer/wp/Service1.svc" binding="basicHttpBinding"
        bindingConfiguration="MyEndPoint" contract="ServiceSSLref.IService1"
        name="MyEndPoint1" behaviorConfiguration="ClientCertificateCredential"/>
</client>

<bindings>
    <basicHttpBinding>
        <binding name="MyEndPoint">
            <security mode="Transport">
                <transport clientCredentialType="Certificate" />
            </security>
        </binding>
    </basicHttpBinding>
</bindings>

<behaviors> 
  <endpointBehaviors> 
    <behavior name="ClientCertificateCredential"> 
      <clientCredentials> 
        <clientCertificate findValue="mycomputer" storeLocation="LocalMachine" storeName="My" x509FindType="FindByIssuerName" />
        <serviceCertificate>
          <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
        </serviceCertificate>
      </clientCredentials> 
    </behavior> 
  </endpointBehaviors> 
</behaviors>
</system.serviceModel>
1个回答

6

我猜想你的问题可能在于客户端证书。当设置clientCredentialType="Certificate"时,你告诉WCF客户端必须指定一份服务器信任的证书。据我所知,你只拥有由服务器生成的证书。尝试设置

 <transport clientCredentialType="None" /> 

这将允许您发送消息,而无需服务器信任证书。或者您可以尝试在客户端上生成证书并将其放入服务器的受信任文件夹中。也许这个状态会有所帮助。 http://msdn.microsoft.com/en-us/library/ms731074.aspx

1
谢谢,我认为那可能是解决那个错误的方法。然而,在同一阶段,我收到了“远程服务器返回意外响应:(405)不允许的方法。”,所以我不确定它是好还是坏。 - Zeezer
请检查您的合约接口中是否有公共关键字。别忘了执行 C:\Windows\Microsoft.NET\Framework\v4.0.30319>ServiceModelReg.exe -i。 - Alex
1
非常感谢!我已经为这个问题苦苦思索了好几天。现在它终于可以工作了,而且最后的问题也很容易解决。我的地址应该是https://mycomputer/wp/Service1.svc,而不是https://mycomputer/wp/。 - Zeezer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接