/// <summary> /// Creates the instance internal. /// </summary> /// <typeparam name="TServiceContract">The type of the service contract.</typeparam> /// <param name="channelFactory">The channel factory.</param> /// <returns></returns> private TServiceContract CreateInstanceInternalClaims <TServiceContract>(ChannelFactory <TServiceContract> channelFactory) { foreach (var operation in channelFactory.Endpoint.Contract.Operations) { var dataContractSerializerOperationBehavior = operation.Behaviors.Find <DataContractSerializerOperationBehavior>(); if (dataContractSerializerOperationBehavior == null) { dataContractSerializerOperationBehavior = new DataContractSerializerOperationBehavior(operation); if (!operation.Behaviors.Contains(dataContractSerializerOperationBehavior)) { operation.Behaviors.Add(dataContractSerializerOperationBehavior); } } dataContractSerializerOperationBehavior.MaxItemsInObjectGraph = Int32.MaxValue; } // Add channelFactory.Endpoint Behaviors if (channelFactory.Endpoint.Behaviors.Find <CallerContextBehavior>() == null) { var endpointBehavior = new CallerContextBehavior(); channelFactory.Endpoint.Behaviors.Add(endpointBehavior); } #if DEBUG if (channelFactory.Endpoint.Behaviors.Find <ProfilerEndpointBehavior>() == null) { var profilerBehaviour = new ProfilerEndpointBehavior(); channelFactory.Endpoint.Behaviors.Add(profilerBehaviour); } #endif // Add channelFactory.Endpoint.Contract.Operations Behaviors // None /* * * var operationBehaviours = new List<IOperationBehavior>(); * * foreach (var operationBehavior in operationBehaviors) * { * foreach (var operation in channelFactory.Endpoint.Contract.Operations) * { * if (!operation.Behaviors.Contains(operationBehavior)) * { * operation.Behaviors.Add(operationBehavior); * } * } * } */ if (channelFactory.Credentials != null) { channelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; } return(channelFactory.CreateChannelWithIssuedToken(GetSecurityTokenDirectFromLocalSts())); }
private TServiceContract GetServiceChannel <TServiceContract>(SecurityToken securityToken, string relyingPartyUrl) where TServiceContract : class { var channelFactory = GetChannelFactory <TServiceContract>(relyingPartyUrl); if (channelFactory.Endpoint.Behaviors.Find <CallerContextBehavior>() == null) { var endpointBehavior = new CallerContextBehavior(); channelFactory.Endpoint.Behaviors.Add(endpointBehavior); } #if DEBUG if (channelFactory.Endpoint.Behaviors.Find <ProfilerEndpointBehavior>() == null) { var profilerBehaviour = new ProfilerEndpointBehavior(); channelFactory.Endpoint.Behaviors.Add(profilerBehaviour); } #endif return(channelFactory.CreateChannelWithActAsToken(securityToken)); }