Getting Up and Running with the XenApp Management SDK
December 11, 2008 2 Comments
I began working on my latest side project a week or so ago. This one involves the XenApp Management SDK (aka MFCOM) with C# and WPF. One of my goals for the project is to maintain compatibility with XenApp 4.5 and 5.0. So I setup XenApp 4.5 on my XenServer and installed the latest and greatest version of the SDK (5.0) on my Vista development box.
I’ve used the SDK in the past, but its been a while so I was a little rusty. I ran mfreg to point the SDK to my server. Then without much thought I wrote some C# code to connect up to my 4.5 farm:
IMetaFrameFarm8 _farm = new MetaFrameFarm();
_farm.Initialize(MetaFrameObjectType.MetaFrameWinFarmObject);
I hit F5 to run my project in Visual Studio and got a little suprise in the form of an InvalidCastException:
Unable to cast COM object of type 'MetaFrameCOM.MetaFrameFarmClass' to interface type 'MetaFrameCOM.IMetaFrameFarm8'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ED62F657-63C2-11D4-94D8-00C04FB0F326}' failed due to the following error: Unable to cast COM object of type 'MetaFrameCOM.MetaFrameFarmClass' to interface type 'MetaFrameCOM.IMetaFrameFarm8'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ED62F657-63C2-11D4-94D8-00C04FB0F326}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Version 8 of IMetaFrameFarm is the latest version of the farm interface for XenApp 5.0. I needed to use an older version of the interface, one that 4.5 shipped with. So I changed IMetaFrameFarm8 to IMetaFrameFarm7 and everything worked fine. Older interfaces are compatible with future versions of XenApp, which means I’m guaranteed my code will work with XenApp 5.0.
That brings us to lesson #1: Each release of XenApp is updated with a new set of interfaces. The interface you use must be <= to the version of XenApp you’re targeting. For example, IMetaFrameFarm7 shipped with XenApp 4.5 and can be used against XenApp 4.5 and 5.0.
Next I wrote some code to iterate through the applications in my farm and ran into the following UnauthorizedAccessException:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
This was due to my Vista machine’s DCOM Default Impersonation Level not being set to Impersonate. It seems Identify is the default in Vista. I changed this by doing the following:
- Open the Component Services MMC snap-in.
- Right click on the My Computer node.
- Select Properties.
- Go to the Default Properties tab.
- Under Default Impersonation Level choose Impersonate.
That brings us to lesson #2: DCOM must be configured properly on the system running the SDK. More information on this can be found in the documentation under Configuring MFCOM Security, which gets installed as part of the SDK.
After addressing these issues the SDK worked great and I was on my way churn out the bits of my project.
Hi.
I have run into the same problem you mention in the beginning of your post. You say you changed from IMetaFrameFarm8 to xx7. But where do you do that. You only have one line of code? Please help me as I’m getting nuts here.
Kinde Regards
Karsten Markmann
I found this in another article and this works great:
Type t = Type.GetTypeFromProgID(“MetaFrameCOM.MetaFrameFarm”);
IMetaFrameFarm7 farm = Activator.CreateInstance(t) as IMetaFrameFarm7;
farm.Initialize(MetaFrameObjectType.MetaFrameWinFarmObject);