У меня простой сервис, и я пытаюсь настроить аутентификацию.На клиенте я хочу, чтобы пользователь ввел свою учетную запись Windows.И WCF будет использовать имя пользователя / пароль, предоставленные клиентом, и аутентифицировать их на основе аутентификации Windows.
Вот мой сервер app.config
<system.serviceModel>
<services>
<service name="WcfService.Service1" behaviorConfiguration="WcfService.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfService/Service1/" />
</baseAddresses>
</host>
<endpoint address ="" binding="wsHttpBinding" contract="WcfService.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode = "Windows"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Вот мой клиент app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1">
<security mode = "Message">
<message clientCredentialType = "UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/Design_Time_Addresses/WcfService/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Вот мой код на клиенте
ServiceReference1.Service1Client client = new WcfAuthentication.ServiceReference1.Service1Client();
client.ClientCredentials.UserName.UserName = "mywindowsusername";
client.ClientCredentials.UserName.Password = "mywindowsuserpassword";
Console.WriteLine(client.GetData(5));
Но я всегда получаю это исключение:
{"Невозможно открыть защищенный канал, потому что сбой согласования безопасности с удаленной конечной точкой. Это может быть связано с отсутствием или неправильно указанным EndpointIdentity в используемом EndpointAddressдля создания канала. Убедитесь, что EndpointIdentity, указанный или подразумеваемый в EndpointAddress, правильно идентифицирует удаленную конечную точку. "} {" Запрос маркера безопасности содержит недопустимые или неправильно сформированные элементы. "}