Automation Error when invoking method on WCF mex Moniker with Excel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 08:32:21

For anyone facing the same problem, here is the solution. I found out the cause of problem myself by a bit of researching, and below is what I did to get around it.

Cause of Problem

(It seems like) programs that use COM interfaces using a moniker string to connect to WCF services have problems with complex types (like classes, structures, arrays etc.). They can only work with simple types only (like string, integer, decimal, boolean etc.). Complex types in either method arguments or return type does not work.

Even if the method you want to call may not have any complex types at all in their method arguments or return type, they will not work if there is at-least one method in the service that has.

In my case, the methods that I was interested in did not have any complex types as method arguments or return types.

My Solution

Once I found out what was causing the problems, finding a solution around it was easy. I just created a separate WCF service (interface) for the methods of my interest and ensured that there are no complex types publicly exposed, i.e. no complex types in method definition - method arguments and return types.

Next I created a class that implements this interface, as with any other WCF service. I derived this class from the original one, so that I don't need to repeat all the business logic implemented there. The only purpose this class solves is to get past the limitation I was facing. It was just a wrapper around the original class with limited number of methods in it. The methods simply called the base class equivalent method and returned the resulting output directly to the client.

Then I modified my app.config file to host this new service, and then replaced the service address in moniker string with this new service address. So, basically I ended up hosting two WCF services - one for the clients that can consume complex types and the other for those that can't.

That's all that was required, and everything is working perfectly OK now. :)


NOTE that this is just based on my own observation, and I could be wrong. There may be something I might be missing, and there could be better ways to get around this problem. If you find that this is the case, feel free to comment or post your solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!