We have developed a COM Object which is an .exe file and runs as a service in background. We are trying to connect to the object using JACOB.
Introduction:
On start up create an activeXcomponent and call Connect method of the object. Connect method returns instance of the class (which is written inside COM object) by reference, here referred as "handle"
component=new ActiveXComponent("ServiceName.className");
Dispatch.call(component,FN_CONNECT,sourceType,additionalParams,handle);
This handle is stored in a class level variable. Instance of this JAVA Class is stored in a connection pool and is later used for future function calls. This is to ensure that the next calls are called on objects/pointers which are already initialized.
When data fetch call is to be initiated, it calls another method named fetchData and takes request as input. It returns error code and response by reference. The component object is referred through the instance of a JAVA class that was stored in the connection pool
Variant response = new Variant("", true); //String
Variant errorCode = new Variant(0, true);
Dispatch.call(component,FETCH_DATA,handle,functionCode,request,response,errorCode);
Problem statement:
Now while testing in local enviroment we found out that everthing works fine as expected and no exception is thrown. However in client enviroment we are getting following error:
Caused by: com.jacob.com.ComFailException: Can't map name to dispid: fetchData
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.callN(Dispatch.java:453)
at com.jacob.com.Dispatch.call(Dispatch.java:541)
We managed to notice that same code works fine at one attempt and fails in next restart. This behavior is completely random hence difficult to trace.
Points to note:
- fetchData function exists with exactly same signature at both side.
- Code runs fine at one point and misbehaves after restart.
We read somewhere, JACOB Library misbehaves in a multi-threaded enviroment. Is this true?
If yes, what should be done in order to make it work as expected. If not, then why is this exception thrown randomly ?
Any idea/help/lead is useful. Thanks in advance!