How do I tell WCF to skip verification of the certificate?

后端 未结 2 1643
Happy的楠姐
Happy的楠姐 2020-12-02 17:16

Trying to make a web service call to an HTTPS endpoint in my Silverlight application results in this error: \"Could not find a base address that matches scheme https for the

2条回答
  •  庸人自扰
    2020-12-02 18:13

    You might be able to achieve this in Silverlight by allowing cross-domain communication between the web server the hosts the Silverlight application and the remote WCF service.

    In that case you need to place a clientaccesspolicy.xml file at the root of the domain where the WCF service is hosted:

    
    
      
        
          
            
          
          
            
          
        
      
    
    

    Here's what MSDN states about this approach:

    To allow access to an HTTPS service from any Silverlight control hosted over HTTP application, you need to put the ” />* element inside your element.

    I haven't tried this myself but it could be worth a shot. Also be sure to check out the following resources for more details:

    • Making a Service Available Across Domain Boundaries
    • Configuring Web Service Usage in Silverlight Clients

    Disabling X.509 certificate validation in .NET

    For .NET applications this sample WCF configuration will disable validation of both whether the certificate is trusted and whether it is still valid on the client:

    
        
          
            
                
                    
                        
                    
                
            
          
        
        
          
        
    
    

    An alternative solution is to provide custom logic to validate the X.509 certificate provided by the service. In that case you will have to modifiy the configuration file according to the following:

    
        
          
            
                
                    
                        
                    
                
            
          
        
        
          
        
    
    

    Then create a class that derives from X509CertificateValidator to implement your custom validation logic.

    public class MyCertificateValidator : X509CertificateValidator
    {
        public override void Validate(X509Certificate2 certificate)
        {
            // Add custom validation logic
            // Throw an exception to fail validation
        }
    }
    

    As always, you can find a more detailed example up on MSDN.

提交回复
热议问题