Visual Studio 2010 で (Cassini Development Server を介して) ビルドおよび実行できる WCF サービス (C#) があります。コンソール クライアント アプリをそのサービスに接続すると、すべてがうまく機能します。サービス自体が単一の COM オブジェクトをロードし、すべてのコードが期待どおりに機能しています (これまでのところ)。
ただし、このサービスを Windows サービスでホストし、sc または installutil を使用して (ローカルまたはリモートで) サービスをインストールし、コンソール クライアント アプリを同じサービスに接続すると、正常に接続および切断されますが、サービスを呼び出すと、 COM オブジェクトをロードするメソッドを実行すると、例外が発生します。Windows サービスまたは IIS7 64 ビットでサービスをホストするたびに、この例外が発生しました。
明らかに、COM オブジェクトは私のマシンで regsvr32 されており、サービスはデバッガーを介してホストされているときに COM オブジェクトを読み込むことができます。COM の読み込みビットにまたがりました。オブジェクトは見栄えがよく、使用しています。この同じ COM オブジェクトを使用する他のアプリケーションもあります。
これは(おそらく)それが(x86).dllであり、私の開発環境が64ビットであり、何らかの理由でCassini開発サーバーがCOMオブジェクトをロードできるという事実と関係があると思いますが、ホストするとサービスを Windows サービスとして、または IIS で、$path$ 変数または何らかの環境の問題により、COM オブジェクトの検索/読み込みが許可されていません。
IIS でホストする場合は、新しいプールを作成して 32 ビット アプリケーションを有効にしましたが、COM オブジェクトの読み込みにはまだ問題がありました。Windows サービスに関しては、何ができるかわかりません...
Google 検索が効果的でない場合はご容赦ください。しかし、この正確な状況を見つけるのに苦労しています。
標準の未登録 COM 例外を次に示します。
System.ServiceModel.FaultException\`1 was unhandled
Message=Retrieving the COM class factory for component with CLSID {BB9F026E-EC18-449F-84AA-677225967C07} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at methodname(String product, String options, Int32 quantity)
at methodname(String product, String options, Int32 quantity) in ...\Reference.cs:line 70
at ....Program.Main(String[] args) in ...\Program.cs:line 72
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: