public ChannelInfo(Type serviceContract, ChannelCredentials credentials) { this.ServiceContract = serviceContract; this.Credentials = credentials; }
/// <summary> /// Creates a channel for the specified contract, using the specified factory. /// Note that this method modifies the factory, therefore it cannot be re-used! /// </summary> /// <param name="serviceContract"></param> /// <param name="factory"></param> /// <param name="credentials"></param> /// <returns></returns> private static IClientChannel CreateChannel(Type serviceContract, ChannelFactory factory, ChannelCredentials credentials) { var authenticationRequired = AuthenticationAttribute.IsAuthenticationRequired(serviceContract); if (authenticationRequired) { factory.Credentials.UserName.UserName = credentials.UserName; factory.Credentials.UserName.Password = credentials.Password; } // invoke the CreateChannel method on the factory var createChannelMethod = factory.GetType().GetMethod("CreateChannel", Type.EmptyTypes); var channel = (IClientChannel)createChannelMethod.Invoke(factory, null); Platform.Log(LogLevel.Debug, "Created service channel instance for service {0}, authenticationRequired={1}, endpoint={2}", serviceContract.Name, authenticationRequired, factory.Endpoint.Address.Uri); // add some identifying information to the channel, in case we are asked to obtain a failover channel channel.Extensions.Add(new ChannelInfo(serviceContract, credentials)); return(channel); }