Condividi tramite


How to talk to FIM/MIM Service Pogrammatically

 

You've probably told more than once that FIM/MIM Service is a WCF Service which exposures several endpoints . Then how can we connect to the WCF service programmatically? In this blog, i will take the Resource Endpoint as a starting point and demo how to invoke Get method.

Firstly, we create a Visual C# console Application and add a service reference to the create a proxy for the running FIMService. After clicking "OK", there are five default endpoints added to the configuration file App.config.

Note: you shall modify the URI according to your fim service host name.

 

 

Next, we need compose a request message by specifying the parameter. As described in the Developer reference page , a Get Request is to retrieve the object by supplying the objectID . Below is the copy of the code snippet.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels;
using GetResourceDemo.FIMServiceReference;
using Microsoft.ResourceManagement;
using Microsoft.ResourceManagement.WebServices;
using System.Xml;

namespace GetResourceDemo
{
    class Program
    {
        static void Main(string[] args)
        {

           //GetAction
            const string GetRCAction = "https://schemas.xmlsoap.org/ws/2004/09/transfer/Get";
            const string RMNameSpace = "https://schemas.microsoft.com/2006/11/ResourceManagement";
           //create a WCF resourceClient by referring the config file
           ResourceClient rc = new ResourceClient("ServiceMultipleTokenBinding_Resource"); 

           //compose the request message
           Message request;
           request = Message.CreateMessage(MessageVersion.Default,GetRCAction );
            // the built-in FIM administrator's account, shared across all the systems
           UniqueIdentifier id = new UniqueIdentifier("7fb2b853-24f0-4498-9534-4e10589723c4");
           request.Headers.Add(MessageHeader.CreateHeader("ResourceReferenceProperty",RMNameSpace, id.ToString(), false)); 

           //invoke the get method
           using (Message responseMessage = rc.Get(request))
           {
               //Parse the reponse messgae
               XmlDictionaryReader fullObject = responseMessage.GetReaderAtBodyContents();
               XmlDocument Xdoc = new XmlDocument();
               Xdoc.Load(fullObject);

               XmlNamespaceManager xmlNamespace = new XmlNamespaceManager(Xdoc.NameTable);
               xmlNamespace.AddNamespace("rm", RMNameSpace);
               XmlNodeList nodes = Xdoc.SelectSingleNode("//rm:Person", xmlNamespace).ChildNodes;
               foreach (XmlNode node in nodes)
               {
                   Console.WriteLine("{0} : {1}", node.Name.ToString().Replace("rm:", ""), node.InnerText.ToString());
               }
           }

           Console.ReadKey();
        }
    }
}

Finally, build the project and run it, you’ll have all the information for the default FIM administrator. :)

Further if you don't want to build the FIM client library from scratch, I would recommend the lithnet FIM client which simplifies the interactive with FIM Service.

Capture

Comments

  • Anonymous
    April 20, 2016
    Unable to find the service reference itself.Provide suggestions.
    • Anonymous
      May 24, 2016
      it (Microsoft.ResourceManagement.dll) is located under "C:\Program Files\Microsoft Forefront Identity Manager\2010\Service"
  • Anonymous
    July 10, 2016
    Great Articles Tracy
    • Anonymous
      July 24, 2016
      Thanks a lot, david :)