Join Now!
Like most of you, you may have looked at the "UserProfileManager" web services and noticed that there is no way to get all the user profiles. I needed this functionality so I decided to create my own web service. So if you need a starter for ten then here we go. Create your web application project so it looks something like this:
Now we need to add the following code:
To make sure that the web service performed better than normal I added some methods that cache the results for a certain time limit. So the core code is this:
We now add the following:
Notice we have started to create the Xml document above. We can now add the XmlElements as needed. This code loops through all of the UserProfiles that exist in the profileManager object and then starts to add XmlElements and attributes as needed.
While doing the code I found that if the profile field had multiple values it would not render them correctly so I had to write some code that would loop through the multiple values and write them out.
Now we have the core XmlDocument created we can then close the document and return it as part of our method.
So now the code is done, we need to add this somewhere. I simply created a new virtual directory in IIS.
I made sure that the directory was using the same Application Pool Account as the rest of the site.
I was then able to run the web service as shown below:
I selected my Xml method then selected the INVOKE option.
Hey Presto, and XmlDocument of my user profiles on my test server.
If I expand one of the users it now lists all the profile fields in the profile as well as their values.
Fantastic, love using Xml to get the data I need. And with some extra caching methods this web service works really well and allows me to get large amounts of data very quickly. I am re-writing this into a WCF service so will blog about it soon. J
Posted on 8/14/2009 at 12:48 PM Permalink | Share This Post | Comments (0) | Leave a Comment
Blog Tags:
Community Tags:
All Blogs
Administration Coding CQWP Download Email How To iPhone Metadata Services MOSS 2007 MOSS Search My Sites Records Management REST Services Search SEO Service Packs SharePoint SharePoint 2010 Toolkit Updates User Experience WCF Web XML