Hello. Using the article as a guide, I try to implement authentication for the WCF service. When I run the application in Visual Studio 2015, I get an exception: "Для конечной точки с привязкой BasicHttpBinding не удалось найти базовый адрес, соответствующий схеме https. Зарегистрированные схемы базовых адресов — [http]." To overcome this problem did not work. Please help.

The contract:

 using System.ServiceModel; namespace Brett.Service { [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); } } 

Service:

 using System; using System.ServiceModel; namespace Brett.Service { public class Service1 : IService1 { public string GetData(int value) { return string.Format("{0} entered: {1}", GetCurrentUserName(), value); } private string GetCurrentUserName() { var primaryIdentity = ServiceSecurityContext.Current.PrimaryIdentity; if (primaryIdentity.IsAuthenticated) { return primaryIdentity.Name; } else { throw new Exception(@"User is not authenticated..."); } } } } 

Validator:

 using System.IdentityModel.Selectors; using System.ServiceModel; namespace Brett.Service { public class CustomValidator : UserNamePasswordValidator { public override void Validate(string userName, string password) { if (userName != @"hello") { throw new FaultException(@"User name must be 'hello'."); } } } } 

Config:

 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <services> <service name="Brett.Service.Service1" behaviorConfiguration="Brett_Behavior"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Brett_BindingConfiguration" contract="Brett.Service.IService1" /> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> </service> </services> <bindings> <basicHttpBinding> <binding name="Brett_BindingConfiguration"> <security mode="TransportWithMessageCredential"> <message clientCredentialType="UserName" /> </security> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="Brett_Behavior"> <serviceMetadata httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true"/> <serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Brett.Service.CustomValidator, Brett.Service"/> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <directoryBrowse enabled="true"/> </system.webServer> </configuration> 
  • You would bring some code. - VladD
  • @VladD, added code. - sp7
  • show the publication code of the service. where do you publish it? In IIS? This error occurs when you publish the service on the http address, although here it expects publication on a secure http (https) - Alexcei Shmakov
  • By publishing code, do you mean a file with the extension .pubxml ? - sp7
  • Not really, where is your service published? in IIS, or do you publish it yourself through ServiceHost? If you did all the article, it turns out in IIS. So the question is, did you configure the service publishing in IIS? Added an https binding with an SSL certificate attached to this point? For some reason it seems to me that you did not. And the reason should be this. - Alexcei Shmakov

0