다음을 통해 공유


How to: Use the Web Service to Retrieve Profile Data of a User

Applies to: SharePoint Server 2010

The following code example shows you how use the User Profile Service Web service to retrieve a user's property data as well as the user's memberships, links, and colleagues.

Before running this code, replace domainname, username, and other placeholders 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

     static void GetUserProfilePropertyData()
        {
            UserProfileWebService.localhost.PropertyData[] properties = 
                myService.GetUserProfileByName("domainname\\username");
            for (int i = 0; i < properties.Length; i++)
            {
                Console.WriteLine(properties[i].Name);
                Console.WriteLine(properties[i].Value);
            }

            Console.Read();
        }
         static void GetUserMemberships()

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

            Console.Read();
        }

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

        static void GetUserLinks()
        {
            UserProfileWebService.localhost.LinkData[] links = 
                myService.GetUserLinks("domainname\\username ");
            for (int i = 0; i < links.Length; i++)
            {
                Console.WriteLine(links[i].Url);
            }

            Console.Read();
        }

See Also

Tasks

How to: Retrieve a User Profile

How to: Retrieve User Profile Properties