<

Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

COM Calling WCF

Published on
13,396 Points
6,796 Views
1 Endorsement
Last Modified:
Approved
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.
1
Comment
Author:Najam Uddin
0 Comments

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Join & Write a Comment

this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month