2011-04-06 124 views
1

我已經創建了一個wcf數據服務並通過HTTP公開,並且需要SSL。 我想通過證書(相互身份驗證)對服務和客戶端進行身份驗證。 我正在使用開發人員證書。 因此,我將服務器的證書添加到客戶的可信人員商店。WCF和SSL相互認證403 - 禁止:訪問被拒絕

但我仍然收到一個異常:「403 - 禁止:訪問被拒絕。」

1 - 這是我的服務器配置:

<system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
      <binding name="webHttpBindingConfig"> 
       <security mode="Transport"> 
        <transport clientCredentialType="Certificate" /> 
       </security> 
      </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 

    </behaviors> 
    <services> 
     <service behaviorConfiguration="" name="PricingDataService"> 
      <endpoint address="https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc" 
       binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig" 
       name="webHttpEndpoint" contract="System.Data.Services.IRequestHandler" /> 
     </service> 
    </services> 

如何使服務器能夠識別客戶端的證書? (它也應該是開發者證書)。

2 - 這裏是我的客戶端配置:

<system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
      <binding name="webHttpBindingConfig"> 
       <security mode="Transport"> 
        <transport clientCredentialType="Certificate" /> 
       </security> 
      </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="clientCredentialBehavior"> 
      <clientCredentials> 
      <clientCertificate storeName="TrustedPeople" storeLocation="LocalMachine" 
           x509FindType="FindBySubjectName" findValue="tempClientcert" /> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <client> 
     <endpoint address="https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc" 
      binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig" 
      contract="System.Data.Services.IRequestHandler" name="" kind="" 
      endpointConfiguration="" behaviorConfiguration="clientCredentialBehavior"> 
      <identity> 
       <dns value="MyServiceSecure"/> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

3-這裏是我用來調用WCF代碼代碼:

> MyServiceContext service = new MyServiceContext (
      new Uri("https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc")); 

service.SendingRequest += this.OnSendingRequest_AddCertificate; 


// 
private void OnSendingRequest_AddCertificate(object sender, SendingRequestEventArgs args) 
    { 
     if (null != ClientCertificate) 
      (args.Request as HttpWebRequest).ClientCertificates.Add(X509Certificate.CreateFromCertFile(@"C:\Localhost.cer");); 
    } 

做我就創建一個證書服務器,然後將其安裝在客戶端上?

回答

1

我覺得你的證書可能是錯誤的,而是由IIS驗證「客戶端證書」下的「SSL設置」的網站要麼設置爲接受或需要開始時(看哪個適合你)。

我相信,爲了您的目的,在IIS中爲服務器創建自簽名證書,然後將此證書導出到.pfx文件並將其安裝到受信任的根目錄中應該可行。

如果不幫你,我想看看這個問題:Using makecert for Development SSL

+0

好了,我創建的服務器證書,並將其導出到客戶機上。如何讓服務器識別並允許客戶端訪問它? (我網站的SSL設置被設置爲Require)。 – Attilah 2011-04-06 22:46:57

+0

我並不確定你卡在哪裏,但首先你需要爲網站創建一個HTTPS綁定,請參閱http://learn.iis.net/page.aspx/144/how-to-set -up-ssl-on-iis-7 /這是否回答你的問題? – Tchami 2011-04-07 07:35:04

+0

我一直在試圖讓服務器識別客戶端的證書。 – Attilah 2011-04-07 12:58:23