private Session CreateSession(
ApplicationConfiguration configuration,
BindingFactory bindingFactory,
ConfiguredEndpoint endpoint,
IUserIdentity identity)
{
Report("Creating new Session with URL = {0}", endpoint.EndpointUrl);
// Initialize the channel which will be created with the server.
ITransportChannel channel = SessionChannel.Create(
configuration,
endpoint.Description,
endpoint.Configuration,
configuration.SecurityConfiguration.ApplicationCertificate.Find(true),
configuration.CreateMessageContext());
// Wrap the channel with the session object.
Session session = new Session(channel, configuration, endpoint, null);
session.ReturnDiagnostics = DiagnosticsMasks.All;
// register keep alive callback.
session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
// create the user identity.
if (identity == null)
{
if (endpoint.Description.UserIdentityTokens.Count > 0)
{
identity = CreateUserIdentity(endpoint.Description.UserIdentityTokens[0]);
}
}
// Create the session. This actually connects to the server.
session.Open(Guid.NewGuid().ToString(), identity);
Report("Successfully created new Session.");
// return the session.
return session;
}