在Windows服务或IIS中托管WCF服务时COM异常0x80040154

时间:2013-04-15 19:28:52

标签: c# wcf iis-7 windows-services

我有一个WCF服务(C#),我可以在Visual Studio 2010中构建和运行(通过Cassini Development Server)。我将控制台客户端应用程序连接到该服务,所有工作都很棒。服务本身加载一个COM对象,我的所有代码都按预期工作(到目前为止)。

但是,如果我在Windows服务中托管此服务并使用sc或installutil(本地或远程)安装服务,然后将控制台客户端应用程序连接到同一服务,它仍然连接并断开连接,但是当我调用加载COM对象的服务方法,我得到一个例外。每当我在Windows服务或IIS7 64位中托管服务时,我都会目睹此异常。

显然,我的机器上的COM对象已被regsvr32'd,并且该服务可以在通过调试器托管时加载COM对象。我甚至踩过COM加载位,对象看起来很棒,我用它。我们还有其他使用相同COM对象的应用程序。

我认为这可能与(x86).dll有关,而且我的开发环境是64位,并且出于某种原因,Cassini Development Server可以加载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:

1 个答案:

答案 0 :(得分:0)

我认为问题在于我没有在Windows的SysWOW64目录中使用特殊的64位程序(仍称为regsvr32)注册.dll。

请参阅: Register 32 bit COM DLL to 64 bit Windows 7

实际上我在发布之前就找到了这个解决方案,并且认为我已经尝试了它并且仍然得到例外,但也许我错了。这个解决方案似乎有效。它甚至可能需要重启服务器或至少重启IIS。