Controlling iTunes with ASP.NET running under IIS

5

I've been trying to control iTunes with ASP.NET with varying levels of success, but none that fits my situation exactly. I've looked around the web and tried all of the provided solutions without much luck. I've tried using many different iTunes COM libraries (even the one that's on Apple's developer website), still no luck. The issue is, when I'm using Visual Studio's development server to create an instance of the iTunes COM object - iTunesApp - it works perfectly and allows me to control iTunes. This also works perfectly in a Console and WinForms app. But as soon as I switch it to use the IIS server, nothing seems to work. I need it to run as a website under ASP.NET so it can receive requests from other devices. This has tremendous potential for building a web app to control and essentially build a Web-based API around iTunes. It throws the following error on creation of a new instance of the iTunesApp class:

Retrieving the COM class factory for component with CLSID {DC0C2640-1415-4644-875C-6F4D769839BA} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

First I was using the iTunes.Interop.dll file that is used in many of the projects around the web. I tried many times without luck and then tried registering the DLL, that threw an error about not finding an entry point into the DLL. So then I found that you have to give permission to the Application Pool Identity that the web app is running under to acces and execute the DCOM service in Windows Component Services. I did that, and also gave access to Everyone, still nothing. Then I tried using the COM library that is installed by iTunes (when you go to Add Reference, instead of browsing to the DLL file, I went under COM tab and selected iTunes Type Library), no luck. I suspect that when I gave permission to the Windows DCOM component, I gave permission to the installed iTunes COM library since Windows recognized that as installed (and I couldn't register the original iTunes.Interop.dll - Windows wouldn't know it was there).

Both, the installed iTunes Type Library and the iTunes.Interop.dll file, gave me the same aforementioned error. Strangely, the CLSID in the error (DC0C2640-1415-4644-875C-6F4D769839BA) doesn't match iTunes's "Application ID", as it is called in Component Services\DCOM\iTunes\Properties window, which is F98206B5-F052-4965-9FA0-85F61BC3C19D. My suspicion is that I'm not giving permission to the correct DCOM component in Windows. I searched my registry for the CLSID in the error and it returns no results, so I concluded that it's not the Application ID of any of the DCOM components (all the Application ID's are under Computer\HKEY_CLASSES_ROOT\Wow6432Node\AppID - didn't find it in there either). But since it's the CLSID in the error, it must be referenced to somewhere, I just couldn't find it anywhere. Searching for either ID on Google isn't helpful either because they both return search results that include iTunes, but none specific enough to the problem.

I even tried the multithreaded approach. Since COM libraries run in STA model and web servers run in MTA, one of the solutions I found suggested to convert the server's thread execution model to STA and then call the COM library. This didn't work either. I have duplicated this problem on 2 computers running completely independent, and on both computers, the Visual Studio Development Server (and Console and WinForms applications) can run it, but IIS cannot.

Here's the code I'm using (without the multithreading):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTunesLib;


namespace NewASPXNetduino2
{
        public partial class _Default : System.Web.UI.Page
        {
                protected void Page_Load(object sender, EventArgs e)
                {
                        Response.Write(WindowsIdentity.GetCurrent().Name + "\n");

                        var iTunes = new iTunesApp();

                        iTunes.Play();
                }
        }
}

The error is throw at the line: var iTunes = new iTunesApp();

If the multithreaded code would help, I can post that too. I'm pretty much directionless at this point and would appreciate any help in any capacity. Thanks.

P.S.: I've already looked around the internet and tried all the solutions I've mentioned above multiple times on multiple computers, so please keep that in mind when replying. Thanks.

asp.net
iis
com
interop
itunes
asked on Stack Overflow Feb 3, 2012 by Anshul • edited Feb 3, 2012 by Anshul

1 Answer

1

I have no experience with the itunes libraries, but the symptoms you describe sound like a security issue to me. IIS is likely running as the local account NETWORK_SERVICE while everything else you mentioned is (probably) running as a regular user account (yours).

To quickly check this, from in IIS manager you can change the account the application pool uses (it's under the identity tab). If this works, then you either need to figure out what is doing the security check and see if you can authorize NETWORK_SERVICE as a valid account, or simply run the application pool using a different account.

answered on Stack Overflow Feb 23, 2012 by gregmac

User contributions licensed under CC BY-SA 3.0