Signing In to a Communications Server

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

When a local Communicator instance is up and running, signing in means connecting the application to the Communicator instance. This is accomplished when the application creates a Messenger object.

If the local Office Communicator 2007 is signed out, the application can call the IMessenger::AutoSignin method to connect Communicator to a Microsoft® Office Communications Server using the preconfigured settings and user credentials. The call logs a user into the Communications Server in the same way as the user does by clicking Sign In on the Connect menu.

In response to a call of the IMessenger::AutoSignin method, Office Communicator Automation API raises an event to inform the application of the status of sign-in request, if the application has registered to receive the DMessengerEvents::OnSignin event and implemented the corresponding event handler.

Signing In from a C# Application

The following C# code snippet illustrates how to sign in to the communications service using Office Communicator Automation API.

// Global or class variable
CommunicatorAPI.MessengerClass communicator;
bool connected = false;

// A simple implementation of signing in.
void Signin(string account, string passwd)
{
   if (connected)
      return;

   if (communicator == null)
   {
      // Create a Messenger object, if necessary
      communicator = new CommunicatorAPI.MessengerClass();

      // Register event handlers for OnSignin and Signout events
      communicator.OnSignin += new DMessengerEvents_OnSigninEventHandler(communicator_OnSignin);
      communicator.OnSignout += new DMessengerEvents_OnSignoutEventHandler(communicator_OnSignout);

      // Register more event handlers as appropriate. (Omitted)
   }
   int parentHandle = 0;
   communicator.AutoSignin();
}

// Event handler for OnSignin event.
void communicator_OnSignin(int hr)
{
   if (hr != 0)
   {
      Console.WriteLine("Signin failed.");
      return;
   }

   connected = true;

   // Display contacts to a console window(for illustration only).
   foreach (IMessengerContact contact in communicator.MyContacts as IMessengerContacts)
   {
      if (!contact.IsSelf)
         Console.WriteLine("{0} ({1})", contact.SigninName, contact.Status);
   }
}

For an example of the event handler for an OnSignout event, see Signing Out from a Communications Server.

See Also

Concepts

Signing Out from a Communications Server