FIM 2010: Programmatic access to FIM Service with Lithnet FIM Service Client library
The Lithnet FIM Service Client is a .NET Library that makes it easy for anyone to program against the FIM web service using any .NET language. It supports create, update, delete, and search operations against the FIM service.
The library has a similar purpose to the FIM 2010 Client, but abstracts away the particulars of the SOAP web service implementation into a robust object model. The development of the FIM 2010 client was abandoned some time ago and unfortunately, the client suffers from a number of bugs and performance issues. This library is not intended to be a drop-in replacement for that library. It is a complete re-write with a new API and more approachable way of working with the objects in the FIM service.
The Lithnet Resource Management Client is designed to be easy to use and help you get started quickly.
- First, create a new project in Visual Studio
- Ensure Microsoft.ResourceManagement.dll is registered in the GAC (you can find this on your FIM service server)
- Install the nuget package from the Package Manager Console in Visual Studio
- Update the app.config or web.config file to point to your FIM service server
<lithnetResourceManagementClient resourceManagementServiceBaseAddress="http://fimsvc-sspr:5725" />
Now you can start coding. This simple app demonstrates the basic get, search, update, and create operations.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lithnet.ResourceManagement.Client;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Create an instance of the resource management client
ResourceManagementClient client = new ResourceManagementClient();
// Get the resource with the account name 'testuser'
ResourceObject resource = client.GetResourceByKey("Person", "AccountName", "testuser");
// Write the object to the console
Console.WriteLine(resource.ToString());
// Get a single attribute
Console.WriteLine(resource.Attributes["AccountName"].StringValue);
// Change an attribute
resource.Attributes["AccountName"].SetValue("NewUsername");
// Save the resource to the fim service
resource.Save();
// Create a new object
ResourceObject newResource = client.CreateResource("Person");
newResource.Attributes["AccountName"].SetValue("MyNewAccount");
newResource.Attributes["Domain"].SetValue("FIM-DEV1");
// Save the new object to the fim service
newResource.Save();
// Search for the newly created object by anchor
ResourceObject foundObject = client.GetResourceByKey("Person", "AccountName", "MyNewAccount");
// Delete the object
client.DeleteResource(foundObject);
// Print the values of the object
Console.WriteLine(foundObject.ToString());
// Search for all Sets
foreach (ResourceObject result in client.GetResources("/Set"))
{
Console.WriteLine(result.ToString());
}
}
}
}
There is a full MSDN-style documentation set available to help you understand the various methods and functions available, and plenty of examples of how to use them. The client is used as the basis for the Lithnet FIM PowerShell module, and the Lithnet FIM Service REST API. If you write an open-source tool using the library, let me know and I'll share it with the community.