Things to know while automating the Transform Manager service

After writing a forum post a little while ago on this topic, I wanted to add an extra level of details and then post a blog.  The issue was pertaining to the intricacies of starting/running the IIS Transform Manager service programmatically such as I was doing in my test automation.   Here it is:

There are a few things to note when you wish to fully automate the IIS Transform Manager service. I can describe briefly what I do for testing internally, but keep in mind the service is not meant to be used as such, and we highly suggest using the User Interface to configure and start the service.

First you would need to make sure the service user credentials that you are using has the following privilege on the machine:

"SeServiceLogonRight"
"SeBatchLogonRight"
"SeAuditPrivilege"
"SeImpersonatePrivilege"

And make sure the user has Full access to the following directory @"%programdata%\Microsoft\IIS\Transform Manager".

Then, obviously the service credentials on the service itself needs to be updated. I use the System.Management.ManagementObject class with the following path "Win32_Service.Name='IISTMHost'" to update the credentials on the service itself. Here's a bare bones snippet that might help point you in the right direction.

   string objPath = string.Format("Win32_Service.Name='{0}'", TMControler.ServiceName);

   using (System.Management.ManagementObject service = new System.Management.ManagementObject(new System.Management.ManagementPath(objPath)))

   {

       object[] wmiParams = new object[11];

       wmiParams[6] = argUser;

       wmiParams[7] = argPass;

       service.InvokeMethod(
"Change", wmiParams);

   }

If you ever plan to use the UI at some point for troubleshooting, monitoring jobs or managing the service; you’ll also need to update the ApplicationHostConfig file to include the service credentials in the “credentials” collection of the system.applicationHost/transformManager section. See %systemdrive%\Windows\System32\inetsrv\Microsoft.Web.Administration.dll for accessing/editing this collection programmatically.  Here's a example of how I used the Microsoft.Web.Administration library.

   using (ServerManager localServer = new ServerManager())

   {

     string attributeNameId = "id";

     string attributeNameUserName = "userName";

     string attributeNamePassword = "password";

     string attributeNameDescription = "description";

     string tmSectionName = "system.applicationHost/transformManager";

     string credentialCollectionName = "credentials";

     bool found = false;

     ConfigurationElement credential = null;

     ConfigurationElementCollection creds = null;

     Configuration config = null;

     ConfigurationSection tmSection = null;

     // Get the the Application Host Config

     config = localServer.GetApplicationHostConfiguration();

     if (config == null)

     {

          //Log("Unable to get the Application Host Config");

     }

     // Get the Transform Manager Section

     tmSection = config.GetSection(tmSectionName);

     if (tmSection == null)

     {

          //Log("Unable to get the Transform Manager Section of the Application Host Config");

     }

     // Get the credentials collection

     creds = tmSection.GetCollection(credentialCollectionName);

     if (creds == null)

     {

          //Log("Unable to get the credentials collection from the Transform Manager Section of the Application Host Config");

     }

     // check if the credential already exists in the collection

     foreach (ConfigurationElement element in creds)

     {

          string elementId = element.GetAttributeValue(attributeNameId).ToString();          if (elementId.Equals(argId))

          {

               credential = element;

               //Log("Found Existing credential in the Transform Manager credentials Collection");

               found = true;               break;

          }

     }

     // if none existed create a new one but don't add it just yet

     if (credential == null)

     {

          credential = creds.CreateElement();

     }

     // Set the attributes

     credential.SetAttributeValue(attributeNameId, argId);

     credential.SetAttributeValue(attributeNameUserName, argUsername);

     credential.SetAttributeValue(attributeNamePassword, argPassword);

     credential.SetAttributeValue(attributeNameDescription, argDescription);

     // now we can add the new credentials after the attributes have been set.

     if (!found)

     {

          creds.Add(credential);

     }

     localServer.CommitChanges();

   }

Now you should be ready to start the service and initialize it. For this you'll need to create a service reference to the IIS Transform Manager service to perform the initialization step. Here's a good blog to get you started if you have not done this already http://blogs.msdn.com/b/giuseppeguerrasio/archive/2011/06/17/monitoring-and-management-services-in-iis-transform-manager-1-0-beta.aspx. Below is a simplified version of my code to start the service and call initialized.

     ServiceController tmService = new ServiceController("IISTMHost");

     tmService.Start();

     tmService.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0,1,0));

// Initialize the service with the service credential

   TMS.ManagementServiceClient managementServiceClient = new TMS.ManagementServiceClient(NetTcpBinding, ManagementEndPointAddress); if (managementServiceClient != null)

   {

     TMS.Credential c = new TMS.Credential()

     {

          Domain = argDomain,

          UserName = argUser,

          Password = argPass,

          Id = argGuid,

          Description = argFullUserName

     };

     managementServiceClient.Open();

     managementServiceClient.InitializeService(c);

     managementServiceClient.Close();

   }

Once started, you can query if the service is properly initialized.

  if(!managementServiceClient.IsServiceInitialized())

  {

      //Log("The Transform Manager Service is not properly initialized");

  }

 

At this point you should have the Transform Manager up and running and ready for more management and/or monitoring. 

 

Published Wednesday, June 13, 2012 1:46 PM by Doiron

Comments

# re: Things to know while automating the Transform Manager service

Thursday, June 28, 2012 5:25 AM by clarence

hi, I wonder what are the values of NetTcpBinding and ManagementEndPointAddress. I don't know how to set them.

# re: Things to know while automating the Transform Manager service

Thursday, June 28, 2012 6:59 PM by Doiron

I have a function that reads them from the actual application config file located here %Program Files%\IIS\Transform Manager\TransformManagerHost.exe.config

You should have all the information you need from that file. I hope this helps!  

Regards,

Mario

# re: Things to know while automating the Transform Manager service

Wednesday, September 5, 2012 2:39 AM by urticaria

I would like to express my appreciation of your writing skill and also ability to make audience, see the whole thing to the end. I'd really like to read more of your blogs and to write about my opinions with you. I'll be your frequent visitor, that's no doubt.

# re: Things to know while automating the Transform Manager service

Thursday, October 18, 2012 2:44 PM by Beats By Dr.Dre Pro

I truly appreciate this post. I抳e been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thank you again

# re: Things to know while automating the Transform Manager service

Sunday, October 21, 2012 7:07 AM by Beats By Dr.Dre Studio

Howdy! I'm at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the fantastic work!

# re: Things to know while automating the Transform Manager service

Sunday, November 4, 2012 9:01 AM by soIRfTRCNxYmEG

aVM7tp Very good blog.Really thank you! Cool.

# re: Things to know while automating the Transform Manager service

Saturday, December 8, 2012 1:37 AM by discount north face jackets

Hi there! This post could not be written any better! Reading through this post reminds me of my good old room mate! He always kept talking about this. I will forward this page to him. Fairly certain he will have a good read. Many thanks for sharing!

# re: Things to know while automating the Transform Manager service

Monday, December 17, 2012 4:45 AM by 車買取

It is a very informative and useful post thanks it is good material to read this post increases my knowledge.

# re: Things to know while automating the Transform Manager service

Friday, February 1, 2013 2:37 AM by swywHtaYYaCCJBnA

Qbbpwg Very informative article post.Really thank you! Want more.

# re: Things to know while automating the Transform Manager service

Thursday, February 21, 2013 6:22 AM by Nowell

hi good page i will definaely come back and see again.

# re: Things to know while automating the Transform Manager service

Wednesday, February 27, 2013 6:25 PM by KrHWJpjpLnYwHjNE

F3XgTT Very good post. Will read on...

# re: Things to know while automating the Transform Manager service

Sunday, March 3, 2013 11:24 PM by xkedhfak@gmail.com

wow! many thanks for that tremendous short article. I actually beloved it with the main. Hope you keep putting up such astonishing articles

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Powered by Community Server (Commercial Edition), by Telligent Systems