使用 IIS 下运行的 ASP.NET 控制 iTunes

发布于 2025-01-01 18:00:59 字数 2585 浏览 1 评论 0原文

我一直在尝试使用 ASP.NET 控制 iTunes,取得了不同程度的成功,但没有一个完全适合我的情况。我浏览了网络并尝试了所有提供的解决方案,但运气不佳。我尝试过使用许多不同的 iTunes COM 库(甚至是 Apple 开发者网站上的库),但仍然没有成功。问题是,当我使用 Visual Studio 的开发服务器创建 iTunes COM 对象 - iTunesApp 的实例时,它运行良好并允许我控制 iTunes。这在控制台和 WinForms 应用程序中也能完美运行。但当我将其切换为使用 IIS 服务器时,似乎没有任何效果。我需要它作为 ASP.NET 下的网站运行,以便它可以接收来自其他设备的请求。这对于构建 Web 应用程序来控制并基本上围绕 iTunes 构建基于 Web 的 API 具有巨大的潜力。创建 iTunesApp 类的新实例时会引发以下错误:

检索具有 CLSID 的组件的 COM 类工厂 {DC0C2640-1415-4644-875C-6F4D769839BA} 由于以下错误而失败: 80080005 服务器执行失败(HRESULT 异常: 0x80080005(CO_E_SERVER_EXEC_FAILURE))。

首先,我使用了 iTunes.Interop.dll 文件,该文件在网络上的许多项目中都使用。我尝试了很多次,但没有成功,然后尝试注册 DLL,这引发了一个关于找不到 DLL 入口点的错误。然后我发现你必须向Web应用程序正在运行的应用程序池身份授予权限才能访问和执行Windows组件服务中的DCOM服务。我这样做了,也给了每个人访问权限,但仍然没有。然后我尝试使用 iTunes 安装的 COM 库(当您转到“添加引用”时,我没有浏览到 DLL 文件,而是在 COM 选项卡下选择了 iTunes 类型库),但没有成功。我怀疑当我向 Windows DCOM 组件授予权限时,我向已安装的 iTunes COM 库授予了权限,因为 Windows 识别出该库已安装(并且我无法注册原始 iTunes.Interop.dll - Windows 不知道它是那里)。

安装的 iTunes 类型库和 iTunes.Interop.dll 文件都给了我同样的上述错误。奇怪的是,错误 (DC0C2640-1415-4644-875C-6F4D769839BA) 中的 CLSID 与 iTunes 的“应用程序 ID”不匹配,因为它是在 Component Services\DCOM\iTunes\Properties 窗口中调用的,这是F98206B5-F052-4965-9FA0-85F61BC3C19D。我怀疑我没有授予 Windows 中正确的 DCOM 组件权限。我在注册表中搜索了错误中的 CLSID,但没有返回任何结果,因此我得出的结论是,它不是任何 DCOM 组件的应用程序 ID(所有应用程序 ID 均位于 Computer\HKEY_CLASSES_ROOT\Wow6432Node\AppID - 也没有在那里找到它)。但由于它是错误中的 CLSID,它必须引用到某个地方,我只是在任何地方都找不到它。在 Google 上搜索任一 ID 也没有帮助,因为它们都会返回包含 iTunes 的搜索结果,但都没有足够具体地解决问题。

我什至尝试了多线程方法。由于COM库在STA模型中运行,而Web服务器在MTA中运行,我发现的解决方案之一建议将服务器的线程执行模型转换为STA,然后调用COM库。这也行不通。我在两台完全独立运行的计算机上重复了这个问题,并且在两台计算机上,Visual Studio Development Server(以及控制台和WinForms应用程序)可以运行它,但IIS不能。

这是我正在使用的代码(没有多线程):

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();
                }
        }
}

错误抛出在以下行: var iTunes = new iTunesApp();

如果多线程代码有帮助,我也可以发布它。我现在几乎没有方向,希望能得到任何帮助。谢谢。

PS:我已经在互联网上浏览并在多台计算机上多次尝试了我上面提到的所有解决方案,所以请在回复时记住这一点。谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2025-01-08 18:00:59

我对 iTunes 库没有任何经验,但您描述的症状对我来说听起来像是一个安全问题。 IIS 可能作为本地帐户 NETWORK_SERVICE 运行,而您提到的其他所有内容(可能)都作为常规用户帐户(您的)运行。

要快速检查这一点,您可以在 IIS 管理器中更改应用程序池使用的帐户(位于“身份”选项卡下)。如果这有效,那么您需要弄清楚是什么在进行安全检查,并查看是否可以将 NETWORK_SERVICE 授权为有效帐户,或者只是使用其他帐户运行应用程序池。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文