Пример #1
0
        /// <summary>
        /// A method used to get the claim provider web service client
        /// </summary>
        /// <returns>A return value represents the claim provider web service client.</returns>
        private ClaimProviderWebServiceClient GetClaimProviderWebServiceClient()
        {
            TransportProtocol currentTransportValue = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", this.Site);
            string            endpointName          = string.Empty;
            string            targetAddressValue    = string.Empty;

            switch (currentTransportValue)
            {
            case TransportProtocol.HTTP:
            {
                endpointName       = Common.GetConfigurationPropertyValue("HttpEndPointName", this.Site);
                targetAddressValue = Common.GetConfigurationPropertyValue("TargetHTTPServiceUrl", this.Site);

                break;
            }

            case TransportProtocol.HTTPS:
            {
                endpointName       = Common.GetConfigurationPropertyValue("HttpsEndPointName", this.Site);
                targetAddressValue = Common.GetConfigurationPropertyValue("TargetHTTPSServiceUrl", this.Site);
                break;
            }
            }

            EndpointAddress targetAddress = new EndpointAddress(targetAddressValue);
            ClaimProviderWebServiceClient protocolClient = WcfClientFactory.CreateClient <ClaimProviderWebServiceClient, IClaimProviderWebService>(this.Site, endpointName, targetAddress);

            // Setting credential
            string userName = Common.GetConfigurationPropertyValue("UserName", this.Site);
            string password = Common.GetConfigurationPropertyValue("Password", this.Site);
            string domain   = Common.GetConfigurationPropertyValue("Domain", this.Site);

            protocolClient.ClientCredentials.Windows.ClientCredential.UserName = userName;
            protocolClient.ClientCredentials.Windows.ClientCredential.Password = password;
            protocolClient.ClientCredentials.Windows.ClientCredential.Domain   = domain;
            protocolClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            protocolClient.Open();

            return(protocolClient);
        }