How to enable Session with SSL wsHttpBinding in WCF

前端 未结 3 1483
-上瘾入骨i
-上瘾入骨i 2020-12-14 11:18

I have a WCF Service with wsHttpBindings and SSL enabled, but I\'d like to enable WCF sessions.

After changing SessionMode to required

SessionMode:         


        
3条回答
  •  我在风中等你
    2020-12-14 12:08

    By default, WSHttpBinding only allows security sessions. It is a concept of WCF and is not linked to Transport. A security session is not a session over https, but a session with mutual authentication. This is achieved by adding message security.

    Based upon your service, you should apply this config

     
          
            
              
                
              
            
          
        
    

    On clientside, here is a simple unit test

    [TestMethod]
        public void TestSecuritySession()
        {
            //remove this is certificate is valid
            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) => { return true; });
    
            var binding = new WSHttpBinding();
            binding.Security = new WSHttpSecurity() { Mode = SecurityMode.TransportWithMessageCredential};
            ChannelFactory Factory = new ChannelFactory(binding, new EndpointAddress("https://localhost/TestService.svc"));
    
            Factory.Open();
            var channel = Factory.CreateChannel();
    
            //call service here
    
            (channel as IClientChannel).Close();
    
            Factory.Close();
        }
    

提交回复
热议问题