示例#1
0
        /// <summary>
        /// Creates a new CurrencyService proxy instance
        /// </summary>
        /// <returns>Nettiers.AdventureWorks.Contracts.Services.ICurrencyService</returns>
        public static Nettiers.AdventureWorks.Contracts.Services.ICurrencyService CurrencyServiceProxyInstance(CommunicationPlatform platform)
        {
            Nettiers.AdventureWorks.Contracts.Services.ICurrencyService proxy = null;

            try
            {
                switch (platform)
                {
                    case CommunicationPlatform.Direct:
                        proxy = new CurrencyService() as ICurrencyService;
                        break;

                    case CommunicationPlatform.WCF:
                        if (factoryCurrencyService == null)
                        {
                            factoryCurrencyService = new ChannelFactory<Nettiers.AdventureWorks.Contracts.Services.ICurrencyService>("CurrencyService");                            
                            factoryCurrencyService.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
                            //factoryCurrencyService.Credentials.Windows.AllowNtlm = true;
                        }

                        if (ClientCredentials != null)
                            factoryCurrencyService.Credentials.Windows.ClientCredential = ClientCredentials;    
                            
                        proxy = factoryCurrencyService.CreateChannel();
                        break;
						
					case CommunicationPlatform.BaseAddress:
                         CustomBinding binding = new CustomBinding(bindingConfigName);
                        //WSHttpBinding binding = new WSHttpBinding("WSHttpBindingConfig");
                        //BasicHttpBinding binding = new BasicHttpBinding("BasicHttpBindingConfig");
                    	EndpointAddress endpoint = new EndpointAddress(BaseAddress + "CurrencyService.svc/gzip");                    
                    	factoryCurrencyService = new ChannelFactory<Nettiers.AdventureWorks.Contracts.Services.ICurrencyService>(binding, endpoint);
                        factoryCurrencyService.Endpoint.Behaviors.Add(new SecurityEndpointBehavior());
                        factoryCurrencyService.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
                        //factoryCurrencyService.Credentials.Windows.AllowNtlm = true;
                        
                        if (ClientCredentials != null)
                            factoryCurrencyService.Credentials.Windows.ClientCredential = ClientCredentials;    
                        
						proxy = factoryCurrencyService.CreateChannel();
						break;
                }
                
                if (proxy != null)
                {
                    OperationContextScope scope = new OperationContextScope((IContextChannel)proxy);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return proxy;
        }
示例#2
0
 /// <summary>
 /// ProxyFactory Constructor
 /// </summary>
 static ProxyFactory()
 {
     try
     {
         string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
         defaultPlatform = (ProxyFactory.CommunicationPlatform)Enum.Parse(
                         typeof(ProxyFactory.CommunicationPlatform),
                         ConfigurationManager.AppSettings["communicationPlatform"]);
     }
     catch { }
 }