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>
.pubxml? - sp7