protected virtual IChannelWrapper <I> ConfigureEndpointFromUri <I>(Uri uri, string channel) where I : class { var clientEndpoint = new ClientEndpoint(); clientEndpoint.Address = uri.ToString(); clientEndpoint.ChannelFactory = channel; return(ConfigureEndpointFromSetting <I>(clientEndpoint)); }
public static ClientEndpoint FindClientEndpoint(Type contractType) { ClientEndpoint result = null; if (ServiceHelpersConfigSection.Settings != null && ServiceHelpersConfigSection.Settings.InProc != null) { foreach (ClientEndpoint endpoint in ServiceHelpersConfigSection.Settings.InProc) { if (endpoint.Contract == contractType.Name || endpoint.Contract == contractType.FullName) { result = endpoint; break; } } } return(result); }
public ClientEndpoint Endpoint(Type t) { ClientEndpoint result = null; if (InProc[t.Name] != null) { result = InProc[t.Name]; } else if (InProc[t.FullName] != null) { result = InProc[t.FullName]; } else if (External[t.Name] != null) { result = External[t.Name]; } else if (External[t.FullName] != null) { result = External[t.FullName]; } return(result); }
/// <summary> /// Configure an endpoint from a setting /// </summary> protected virtual IChannelWrapper <I> ConfigureEndpointFromSetting <I>(ClientEndpoint endpoint) where I : class { IChannelWrapper <I> result = null; if (!string.IsNullOrWhiteSpace(endpoint.Implementation)) { Type t = Type.GetType(endpoint.Implementation); if (t == null) { throw new InvalidOperationException( string.Format( "Unable to create service type, your configuration for endpoint.Implementation is probably wrong or you need to add a reference to an assembly. Configured as {0}.", endpoint.Implementation)); } if (endpoint.UseWcf) { result = CreateInProcWrapper <I>(t); } else { result = new MockChannelWrapper <I>() { Instance = Activator.CreateInstance(t) as I }; } } else if (!string.IsNullOrWhiteSpace(endpoint.Address)) { if (string.IsNullOrWhiteSpace(endpoint.ChannelFactory)) { IServiceHelperAttribute configureHelper = new DefaultServiceHelperAttribute(); Binding binding = null; ClientProxy <I> proxy = null; EndpointIdentity identity = null; var attributes = typeof(I).GetCustomAttributes(false); foreach (var attribute in attributes) { if (attribute is IServiceHelperAttribute) { configureHelper = attribute as IServiceHelperAttribute; identity = configureHelper.CreateIdentity(); } } if (endpoint.Address.StartsWith("net.tcp://")) { binding = new NetTcpBinding() { MaxBufferPoolSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, }; MaxSetter.SetMaxes(binding); } else if (endpoint.Address.StartsWith("http://") || endpoint.Address.StartsWith("https://")) { binding = new WS2007HttpBinding(SecurityMode.None) { MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, }; MaxSetter.SetMaxes(binding); MaxSetter.SetTimeouts <I>(binding); } else if (endpoint.Address.StartsWith("net.msmq://")) { binding = new NetMsmqBinding() { MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, }; } else if (endpoint.Address.StartsWith("net.pipe://")) { binding = new NetNamedPipeBinding() { MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, }; } configureHelper.ConfigureClientBinding(binding, typeof(I)); proxy = new ClientProxy <I>( binding, new EndpointAddress(new Uri(endpoint.Address), configureHelper.CreateIdentity())); configureHelper.ConfigureClientCredentials(proxy.ClientCredentials, typeof(I)); result = proxy; } else { var cfType = Type.GetType(endpoint.ChannelFactory); if (cfType == null) { throw new ConfigurationErrorsException("ChannelFactory is invalid"); } var cf = Activator.CreateInstance(cfType) as ICustomChannelFactory; if (cf == null) { throw new ConfigurationErrorsException("Could not create custom channel factory."); } result = cf.CreateChannel <I>(endpoint); } } if (result != null) { result.CacheCount = endpoint.CacheCount; } return(result); }