2013-04-15 68 views
0

我有一個WCF服務(C#),我可以在Visual Studio 2010(通過Cassini Development Server)中構建和運行WCF服務。我將控制檯客戶端應用程序連接到該服務,並且所有工作都很棒服務本身加載一個COM對象,並且所有代碼都按預期工作(到目前爲止)。但是,如果我在Windows服務中託管此服務並使用sc或installutil(本地或遠程)安裝服務,然後將控制檯客戶端應用程序連接到同一服務,它仍會連接並斷開連接,但是當我調用加載COM對象的服務方法,我得到一個異常。無論何時我將這項服務託管在Windows服務或IIS7 64位中,我都會目睹此異常。在Windows服務或IIS中託管WCF服務時發生COM異常0x80040154

很明顯,COM對象已經在我的機器上運行了,並且服務可以在通過調試器託管時加載COM對象。我甚至跨越了COM加載位,該對象看起來很棒,我使用它。我們也有其他的應用程序使用這個相同的COM對象。

我認爲這可能與(x86).dll以及我的開發環境是64位有關,並且出於某種原因,Cassini Development Server可以加載COM對象,但是當我將該服務作爲Windows服務託管或在IIS中託管時,$ path $變量或某個環境問題不允許它查找/加載COM對象。

至於在IIS中託管時,我做了一個新的池和啓用32位應用程序,但我仍然無法加載COM對象。至於Windows服務我不知道我能做什麼...

對不起,如果我的谷歌搜索沒有效果,但我一直無法找到這種確切的情況。

這裏是標準中沒有註冊的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: 
+0

抱歉張貼太多,嚇跑每個人。我只是想盡可能詳細。 – delrocco

回答

0

我認爲,問題是,我沒有用特殊的64位程序(仍稱REGSVR32)註冊.dll文件,裏面的Windows的SysWOW64目錄。

參見: Register 32 bit COM DLL to 64 bit Windows 7

其實我發現這個解決方案我張貼之前,我想我會嘗試過了,仍然得到例外,但也許我錯了。這個解決方案似乎已經奏效。它甚至可能需要重新啓動服務器或至少重新啓動IIS。