Hallo Zusammen
Ich habe ein COM Object (Interop.SOK.dll von SESAM), welches ich folgendermassen instanziere:
Ich Caste das über Reflection erzeugte Object mit dem Interface Mandant. Wenn ich nun diesen Code innerhalb einer WindowsForm aufrufe, so funktioniert dies.
Wenn ich nun diesen Code über einen Webservice aufrufe, so erhalte ich folgende Fehlermeldung (Webservice läuft bei mir lokal):
System.Web.Services.Protocols.SoapException: Die Anforderung konnte vom Server nicht verarbeitet werden. ---> System.InvalidCastException: Das COM-Objekt des Typs "Interop.FibuSDK.OMandantClass" kann nicht in den Schnittstellentyp "Interop.FibuSDK.Mandant" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{4E879FE0-A269-11CE-AB56-00608CDFDCF8}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).
bei System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
bei System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
bei System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
bei Interop.FibuSDK.OMandantClass.Login(Int16 Typ, Object Pfad, Object Passwort)
bei ch.schwarzer.kmu.be.sesam.impl.DefaultSesamAccessL ayer..ctor(SESAM_DATEI aType, String aMandantPath, String aPassword) in C:\Projects\Schwarzer\Application\KmuDatabase\src\ DefaultSesamAccessLayer.cs:Zeile 42.
bei ch.schwarzer.kmu.be.sesam.impl.DefaultSesamAccessL ayer..ctor(String aMandantPath, String aPassword) in C:\Projects\Schwarzer\Application\KmuDatabase\src\ DefaultSesamAccessLayer.cs:Zeile 25.
bei ch.schwarzer.kmu.bl.service.kontakt.impl.DefaultMa nageKontakt..ctor() in C:\Projects\Schwarzer\Application\KmuBusinessLogic \src\DefaultManageKontakt
.cs:Zeile 36.
bei ch.schwarzer.kmu.bl.service.impl.DefaultServerServ iceLocator.InitializeBusinessLogicServices() in C:\Projects\Schwarzer\Application\KmuBusinessLogic \src\DefaultServerService
Locator.cs:Zeile 63.
bei ch.schwarzer.kmu.bl.service.impl.DefaultServerServ iceLocator..ctor() in C:\Projects\Schwarzer\Application\KmuBusinessLogic \src\DefaultServerService
Locator.cs:Zeile 30.
bei ch.schwarzer.kmu.service.kontakt.ServiceKontakt..c tor() in C:\Projects\Schwarzer\Application\KmuService\Servi ceKontakt.asmx.cs:Zeile 35.
--- Ende der internen Ausnahmestapelüberwachung --- (mscorlib)
------------------------------
Program Location:
Server stack trace:
bei System.ServiceModel.Channels.ServiceChannel.Handle Reply(ProxyOperationRuntime operation, ProxyRpc& rpc)
bei System.ServiceModel.Channels.ServiceChannel.EndCal l(String action, Object[] outs, IAsyncResult result)
bei System.ServiceModel.Channels.ServiceChannelProxy.I nvokeEndService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
bei System.ServiceModel.Channels.ServiceChannelProxy.I nvoke(IMessage message)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage reqMsg, IMessage retMsg)
bei System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData& msgData, Int32 type)
bei ch.schwarzer.kmu.cl.ServiceKontakt.ServiceKontaktS oap.EndGetAllKontaktVo(IAsyncResult result)
bei ch.schwarzer.kmu.cl.ServiceKontakt.ServiceKontaktS oapClient.EndGetAllKontaktVo(IAsyncResult result) in C:\Projects\Schwarzer\Application\KmuClient\Servic e References\ServiceKontakt\Reference.cs:Zeile 1693.
bei ch.schwarzer.kmu.cl.service.contact.proxy.impl.Def aultManageKontaktProxy.EndDetermineAllKontakte(IAs yncResult anResult) in C:\Projects\Schwarzer\Application\KmuClient\src\co ntact\DefaultManageKontak
tProxy.cs:Zeile 87.
Ich habe gelesen, dass gewisse COM Objekte im STA Thread angesprochen werden müssen. Ich habe deshalb die Instanzierung und Aufruf in einen neuen Thread verlagert und dem Thread den ApartmentState STA zugewiesen. Hat leider nichts gebracht.
Weshalb funktioniert der Methodenaufruf auf das COM Object über einen Webservice nicht mehr?
Danke & Grüsse
Pascal
Ich habe ein COM Object (Interop.SOK.dll von SESAM), welches ich folgendermassen instanziere:
Code:
Type mandantType = Type.GetTypeFromProgID("FibuNT.Mandant"); Mandant mandant = (Mandant)Activator.CreateInstance(mandantType); int result = mandant.Login((short)aType, aMandantPath, aPassword);
Wenn ich nun diesen Code über einen Webservice aufrufe, so erhalte ich folgende Fehlermeldung (Webservice läuft bei mir lokal):
System.Web.Services.Protocols.SoapException: Die Anforderung konnte vom Server nicht verarbeitet werden. ---> System.InvalidCastException: Das COM-Objekt des Typs "Interop.FibuSDK.OMandantClass" kann nicht in den Schnittstellentyp "Interop.FibuSDK.Mandant" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{4E879FE0-A269-11CE-AB56-00608CDFDCF8}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).
bei System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
bei System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
bei System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
bei Interop.FibuSDK.OMandantClass.Login(Int16 Typ, Object Pfad, Object Passwort)
bei ch.schwarzer.kmu.be.sesam.impl.DefaultSesamAccessL ayer..ctor(SESAM_DATEI aType, String aMandantPath, String aPassword) in C:\Projects\Schwarzer\Application\KmuDatabase\src\ DefaultSesamAccessLayer.cs:Zeile 42.
bei ch.schwarzer.kmu.be.sesam.impl.DefaultSesamAccessL ayer..ctor(String aMandantPath, String aPassword) in C:\Projects\Schwarzer\Application\KmuDatabase\src\ DefaultSesamAccessLayer.cs:Zeile 25.
bei ch.schwarzer.kmu.bl.service.kontakt.impl.DefaultMa nageKontakt..ctor() in C:\Projects\Schwarzer\Application\KmuBusinessLogic \src\DefaultManageKontakt
.cs:Zeile 36.
bei ch.schwarzer.kmu.bl.service.impl.DefaultServerServ iceLocator.InitializeBusinessLogicServices() in C:\Projects\Schwarzer\Application\KmuBusinessLogic \src\DefaultServerService
Locator.cs:Zeile 63.
bei ch.schwarzer.kmu.bl.service.impl.DefaultServerServ iceLocator..ctor() in C:\Projects\Schwarzer\Application\KmuBusinessLogic \src\DefaultServerService
Locator.cs:Zeile 30.
bei ch.schwarzer.kmu.service.kontakt.ServiceKontakt..c tor() in C:\Projects\Schwarzer\Application\KmuService\Servi ceKontakt.asmx.cs:Zeile 35.
--- Ende der internen Ausnahmestapelüberwachung --- (mscorlib)
------------------------------
Program Location:
Server stack trace:
bei System.ServiceModel.Channels.ServiceChannel.Handle Reply(ProxyOperationRuntime operation, ProxyRpc& rpc)
bei System.ServiceModel.Channels.ServiceChannel.EndCal l(String action, Object[] outs, IAsyncResult result)
bei System.ServiceModel.Channels.ServiceChannelProxy.I nvokeEndService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
bei System.ServiceModel.Channels.ServiceChannelProxy.I nvoke(IMessage message)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage reqMsg, IMessage retMsg)
bei System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData& msgData, Int32 type)
bei ch.schwarzer.kmu.cl.ServiceKontakt.ServiceKontaktS oap.EndGetAllKontaktVo(IAsyncResult result)
bei ch.schwarzer.kmu.cl.ServiceKontakt.ServiceKontaktS oapClient.EndGetAllKontaktVo(IAsyncResult result) in C:\Projects\Schwarzer\Application\KmuClient\Servic e References\ServiceKontakt\Reference.cs:Zeile 1693.
bei ch.schwarzer.kmu.cl.service.contact.proxy.impl.Def aultManageKontaktProxy.EndDetermineAllKontakte(IAs yncResult anResult) in C:\Projects\Schwarzer\Application\KmuClient\src\co ntact\DefaultManageKontak
tProxy.cs:Zeile 87.
Ich habe gelesen, dass gewisse COM Objekte im STA Thread angesprochen werden müssen. Ich habe deshalb die Instanzierung und Aufruf in einen neuen Thread verlagert und dem Thread den ApartmentState STA zugewiesen. Hat leider nichts gebracht.
Weshalb funktioniert der Methodenaufruf auf das COM Object über einen Webservice nicht mehr?
Danke & Grüsse
Pascal
Comment