Go Premium for a chance to win a PS4. Enter to Win


COM Calling WCF

Published on
13,354 Points
1 Endorsement
Last Modified:
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any questions.

WCF can not be directly called by VB6; we need to create a .NET bridge for it.  Below is how to create that bridge.

Create a .NET Class Library project

1. What all functionality are intended to be used in COM, create an interface for it.  The interface should be public and with the [ComVisible(true)] attribute.  If WCF is to be called, then this interface will be same as the contract interface in WCF (except attributes OperationContract and ServiceContract will not be added in .NETBridge interface.)
2. Create .NET class implementing this interface. (Here write all functionality i.e. logic, call service, hit db …)
3. Class should be public and should have following attributes
   a. [ClassInterface(ClassInterfaceType.None)]
   b. [Guid("<A GUID>")]
   c. [ComVisible(true)]
4. In Visual Studio, right click the project node in Solution Explorer.  Go to Properties -> Signing
5. Check Sign the assembly. Create a new key (using the dropdown control).
6. Build your application.
7. Open Visual Studio command prompt.
8. Use regasm /tlb:<urDesiredTLB>.tlb  <urDLL>.dll   i.e.
      regasm /tlb: wcfCaller.tlb wcfCaller.dll
to generate the TLB file.

(Optional but recommended) in Visual Studio 6 tools, open OLE View and check your TLB.  It should contain your functions, and other stuff, dont worry about the format it looks.
9. The regasm utility will create a type library and register it in your Windows registry to make the classes in wcfCaller.dll available to COM clients.
10. Register to GAC gacutil /i wcfCaller.dll

Create a VB6 project

1. Create a vb project
2. To use .NET component, go to Project -> References. Search for your .NET component. Select it.
3. Create a new object of .NET class and call functions. use createObject for creating instance of .net component.

Issues Faced and Solutions Found

VB6 giving Automation error : - VB6 is not able to create instance of .NET class, your class must have empty constructor.
Unable to connect with web service: - .NET component calls web service by help of entries in its app.config. When service reference is added, it updates app.config. But when you register .NET component in gac it does not takes its config with it.

To make it able to connect with webservice, copy you .net component app.config and place it with VB6 exe with name .exe.config. Reason is dll executes inside calling process hence can access calling exe's config.
Author:Najam Uddin

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month