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. 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 ServicesDCOMiTunesProperties 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 ComputerHKEY_CLASSES_ROOTWow6432NodeAppID – 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 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.
Hi
Here is a good article about how to use ItunesLib
http://blogs.msdn.com/b/noahc/archive/2006/07/06/automating-itunes-with-c-in-net.aspx
hope it hlepful.
Yeah I’ve already seen that article. Like I said, I can get it to work in a console application, but it fails to work under IIS. Believe me, I’ve looked everywhere on the web for about 2 weeks and visited almost every link about this topic and tried every
technique, that’s why I’ve come to the forums, because none of these links seem to help me in this exact situation. Running it under a Console App OR the Visual Studio Web Server works, but it doesn’t work when I run it as an ASP.NET application under IIS.
Thanks anyways, I know this is not a very common issue.