Share via


How to: Use the Web Service to Find What's Common Between Two User Profiles

The User Profile Service Web service provides several methods that you can use to find the common manager, common memberships, and common contacts in user profiles remotely.

Before using this code, replace domainname and username with actual values. Also add a Web reference to the following in your Microsoft Visual Studio project:

  • Userprofileservice - The Web service is located at http://<site URL>/_vti_bin/userprofileservice.asmx.

Example

using System;
using System.Collections.Generic;
using System.Text;

namespace UserProfileWebServiceApp
{
    class Program
    {
        public static localhost.UserProfileService myService = 
            new localhost.UserProfileService();
        static void Main(string[] args)
        {

            myService.Credentials = 
                System.Net.CredentialCache.DefaultCredentials;
            FindCommonColleagues();
            FindCommonManager();
            FindCommonMemberships();
            FindInCommon();

        }
        static void FindCommonColleagues()
        {
            UserProfileWebService.localhost.ContactData[] contacts = 
                myService.GetCommonColleagues("domainname\\username");
            for (int i = 0; i < contacts.Length; i++)
            {
                Console.WriteLine(contacts[i].Name);
            }

            Console.Read();

        }

        static void FindCommonManager()
        {
            UserProfileWebService.localhost.ContactData contact = 
                myService.GetCommonManager("domainname\\username");
            Console.WriteLine(contact.Name);


            Console.Read();

        }

        static void FindCommonMemberships()
        {
            UserProfileWebService.localhost.MembershipData[] 
                memberships = 
                myService.GetCommonMemberships("domainname\\username");
            for (int i = 0; i < memberships.Length; i++)
            {
                Console.WriteLine(memberships[i].DisplayName);
            }

            Console.Read();

        }
        static void FindInCommon()
        {
            UserProfileWebService.localhost.InCommonData incommon = 
                myService.GetInCommon("domainname\\username");

            for (int i = 0; i < incommon.Colleagues.Length; i++)
            {
                Console.WriteLine(incommon.Colleagues[i].Name);
            }

            Console.Read();

        }
    }
}

See Also

Tasks

How to: Retrieve What's Common Between Two User Profiles