简体   繁体   中英

How to connect To Skype For Business using UCMA

I have a problem when I call LyncClient.Get() from a Windows Service project, knowing that it works well if I test on a console application.

 var lyncClient = LyncClient.GetClient();
            Dictionary<PublishableContactInformationType, object> statusData =
                new Dictionary<PublishableContactInformationType, object>
                {
                    {PublishableContactInformationType.LocationName, _position},
                    {PublishableContactInformationType.Availability, ContactAvailability.Busy}
                };

The exception I get is:

Microsoft.Lync.Model.ClientNotFoundException: The host process is not running at Microsoft.Lync.Model.LyncClient.EnsureOI () to Microsoft.Lync.Model.LyncClient.GetClient (Boolean sideBySideLync)

When doing research I read that in Windows service, we cannot get the Lync client by calling GetClient() because the service process and Lync process are in different sessions, that's why I'm trying to work with UCMA or UCWA but I do not understand how it works!

You are not talking about UCMA , you are talking about the Lync Client SDK .

You can think of the SDK's as such:

  • Lync Client SDK

This SDK allows you to remote control the standard "Lync Client". You can use this SDK to automate the Lync Client for a user to do whatever you can to do OR to extend the functionality of the Lync Client (kind-of limited). To use this SDK the Lync Client must be running in the user you wish to automate / extend. You can't really run it in a windows service context.

Also all Lync Client applications "share" the one Lync Client "session".

There is an option to run the Lync Client SDK in a " side by side " mode, but that mode is very very limited (ie no UI) and in most cases is not that useful.

  • UCMA

This SDK is a SIP endpoint SDK. It allows you to create and use two main type types of SIP endpoints:

  • User Endpoints
  • Trusted Application Endpoints

With sip endpoints you can do almost everything that a Lync Client SDK can do when automating the Lync Client (ie make calls, answer calls, set presence, subscribe to presence changes, etc, etc). There are some limitations, no video call support. Makes it harder to handle some situations.

UCMA allows you to create "trusted applications" that allow you to create sip endpoints used to extend S4B infrastructure. "trusted applications" / "trusted application endpoints" are "trusted" within S4B and are allowed to do things that you can't normally do with a simple UCMA application eg IVR

So it depends on what you are trying to do depends on what SDK you should use.

UCMA applications can be used in windows service applications.

UCWA is a web SDK version of UCMA (kind-of). The UCWA is a lot more limited than the UCMA SDK but UCWA works for Skype for Business Online whereas the UCMA doesn't directly work with Skype for Business Online. You can get UCMA working with Skype for Business Online using federation but that requires on-premise S4B setup federated to Skype for Business Online which is a lot of work.

Update: To answer the comment question, location is part of the " presence ". So what you need to do to set the location is to set the current presence with a location. For UCWA, see this MSDN link on setting the presence . Following the example, change which link you use to the " location " href and post something like:

{"location":"my new location"}

What I am trying to do in my application is to change the position of the skype user from a service. As it is not possible to do it with Lync Client SDK, I have to work with UCWA SDK but I can't find an example that i can follow him, A suggestion !

Why do you do it using a service? You could do it with a small console application that would be running in the background and invisible, and started at session startup. This way you wouldn't need to know the user's login/password, you only need to poll in your code to wait for the Skype for Business client to be started (which I assume would be shortly after the session start)

Here is an example of what I mean :

class Program
{
    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    [DllImport("Kernel32")]
    private static extern IntPtr GetConsoleWindow();

    const int SW_HIDE = 0;

    static void Main(string[] args)
    {
            // Let's hide the console window first ...
            IntPtr hwnd;
            hwnd = GetConsoleWindow();
            ShowWindow(hwnd, SW_HIDE);

            // I recommend you start a separate thread from here, I removed it for the sake of simplicity
            Boolean clientConnected = false;

            while (!clientConnected)
            {

               try
               {
                  LyncClient lyncClient = LyncClient.GetClient();
                  clientConnected = true;

        // Do your stuff here...

               }
               catch (ClientNotFoundException ex)
               {
                  // Client not found : the client is probably not running...
                  // There is nothing to do besides wait and expect to have the user starting his client...
                  clientConnected = false; // not needed, just to highlight the fact that we are not connected yet

               }
            // Don't forget to make your application sleep/do nothing on regular intervals to avoid taking 100% CPU time while you are polling
           }
}

Of course users could manually kill the application by looking at their Task Manager, but most end users don't do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM