Có thể sử dụng 2 loại xác thực: cửa sổ và Tên người dùng trong wcf, sử dụng Chế độ bảo mật thư và chứng chỉ để xác thực. xác thực UserName My cfg/mã trông:
server cfg:
WCF Xác thực hỗn hợp Tên người dùng và WIndows
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceCredentialsBehavior">
<serviceCredentials>
<serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Util.CustomUserNameValidator, Util" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MessageAndUserName">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client/>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
Khách hàng cfg:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="LocalCertValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" >
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:48097/WCFServer/Service.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService"
contract="ServiceReference1.IService"
name="WSHttpBinding_IService" behaviorConfiguration="LocalCertValidation">
<identity>
<dns value ="cool" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
gì thay đổi, máy chủ để biết cửa sổ sắc mà truy cập vào nó?
Không có tác dụng. Có lẽ tôi không đặt đúng thông tin đăng nhập cửa sổ và cách truy xuất thông tin từ máy chủ? – croisharp
Bạn có thực sự cần 2 phương pháp xác thực khác nhau không? Bạn có thể chuyển thông tin đăng nhập cửa sổ của ứng dụng khách đến dịch vụ và cho phép dịch vụ [mạo danh người dùng] (http://www.danrigsby.com/blog/index.php/2008/04/17/impersonate-a-clients- identity-in-wcf /). Đây có thể là giải pháp tốt hơn so với cố gắng kết hợp và khớp các loại xác thực. Nếu bạn muốn xác minh tên người dùng, bạn có thể lưu trữ chúng trong cơ sở dữ liệu và so sánh chúng với các chi tiết người dùng của khách hàng giả mạo trong đối tượng được trả về từ 'WindowsIdentity.GetCurrent()' (tốt hơn là lưu trữ sid, vì tên người dùng có thể thay đổi) – Franchesca
Có tôi cần 2 auth. phương pháp + ủy quyền với NetSqlAzMan, nhưng tôi biết tất cả làm thế nào để làm, đây là vấn đề của tôi với xác thực hỗn hợp .. – croisharp