<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="MyOwnBehavior"> <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /> <serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WcfService_Project.UNValidator,WcfService_Project" /> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors> <bindings> <wsHttpBinding> <binding name="MyOwnBinding"> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None" /> <message clientCredentialType="UserName" /> </security> </binding> </wsHttpBinding> </bindings> <services> <service behaviorConfiguration="MyOwnBehavior" name="WcfService_Project.Service1"> <endpoint address="https://localhost/WcfService_Project/Service1" binding="wsHttpBinding" bindingConfiguration="MyOwnBinding" name="TestWCFService.Http" contract="WcfService_Project.IService1" /> <host> <baseAddresses> <add baseAddress="https://localhost/WcfService_Project/Service1" /> </baseAddresses> </host> </service> </services> </system.serviceModel> <system.web> <compilation debug="true" /> </system.web> <system.webServer> <directoryBrowse enabled="true" /> </system.webServer> </configuration>
<pre lang="c#">
EndpointAddress ep = new EndpointAddress(new Uri( "https://localhost/Service1.svc?wsdl")); //transport encrypting with SOAP message authentication WSHttpBinding bind = new WSHttpBinding( SecurityMode.TransportWithMessageCredential); //10 sec timeouts bind.ReceiveTimeout = new TimeSpan(0, 0, 10); bind.SendTimeout = new TimeSpan(0, 0, 10); bind.BypassProxyOnLocal = false; // to be able bedugging eg. with fiddler bind.UseDefaultWebProxy = true; //use default system proxy //this we need for our custom credentials bind.Security.Message.ClientCredentialType = MessageCredentialType.UserName; ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client(bind, ep); obj.ClientCredentials.UserName.UserName = "test"; obj.ClientCredentials.UserName.Password = "best"; return obj;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)