/// <summary> /// Creates a new CustomerAddressService proxy instance /// </summary> /// <returns>Nettiers.AdventureWorks.Contracts.Services.ICustomerAddressService</returns> public static Nettiers.AdventureWorks.Contracts.Services.ICustomerAddressService CustomerAddressServiceProxyInstance(CommunicationPlatform platform) { Nettiers.AdventureWorks.Contracts.Services.ICustomerAddressService proxy = null; try { switch (platform) { case CommunicationPlatform.Direct: proxy = new CustomerAddressService() as ICustomerAddressService; break; case CommunicationPlatform.WCF: if (factoryCustomerAddressService == null) { factoryCustomerAddressService = new ChannelFactory<Nettiers.AdventureWorks.Contracts.Services.ICustomerAddressService>("CustomerAddressService"); factoryCustomerAddressService.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; //factoryCustomerAddressService.Credentials.Windows.AllowNtlm = true; } if (ClientCredentials != null) factoryCustomerAddressService.Credentials.Windows.ClientCredential = ClientCredentials; proxy = factoryCustomerAddressService.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 + "CustomerAddressService.svc/gzip"); factoryCustomerAddressService = new ChannelFactory<Nettiers.AdventureWorks.Contracts.Services.ICustomerAddressService>(binding, endpoint); factoryCustomerAddressService.Endpoint.Behaviors.Add(new SecurityEndpointBehavior()); factoryCustomerAddressService.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; //factoryCustomerAddressService.Credentials.Windows.AllowNtlm = true; if (ClientCredentials != null) factoryCustomerAddressService.Credentials.Windows.ClientCredential = ClientCredentials; proxy = factoryCustomerAddressService.CreateChannel(); break; } if (proxy != null) { OperationContextScope scope = new OperationContextScope((IContextChannel)proxy); } } catch (Exception ex) { throw ex; } return proxy; }