COM Calling WCF

AID: 3179
  • Status: Published

2770 points

  • Bynajam_ftp
  • TypeTutorial
  • Posted on2010-05-27 at 23:42:50
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.

Asked On
2010-05-27 at 23:42:50ID3179
Tags

COM

,

WCF

,

VB6

,

tlb

Topic

C# Programming Language

Views
2107

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top C# Experts

  1. kaufmed

    566,376

    Sage

    500 points yesterday

    Profile
    Rank: Genius
  2. BuggyCoder

    240,764

    Guru

    10 points yesterday

    Profile
    Rank: Sage
  3. navneethegde

    158,560

    Guru

    0 points yesterday

    Profile
    Rank: Wizard
  4. CodeCruiser

    140,708

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  5. TheLearnedOne

    137,350

    Master

    2,800 points yesterday

    Profile
    Rank: Savant
  6. wdosanjos

    124,511

    Master

    3,500 points yesterday

    Profile
    Rank: Genius
  7. AndyAinscow

    107,357

    Master

    0 points yesterday

    Profile
    Rank: Genius
  8. Dhaest

    98,335

    Master

    0 points yesterday

    Profile
    Rank: Genius
  9. Idle_Mind

    91,914

    Master

    0 points yesterday

    Profile
    Rank: Savant
  10. tommyBoy

    90,068

    Master

    0 points yesterday

    Profile
    Rank: Genius
  11. nishantcomp2512

    89,000

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  12. MlandaT

    86,553

    Master

    0 points yesterday

    Profile
    Rank: Genius
  13. Chinmay_Patel

    80,818

    Master

    0 points yesterday

    Profile
    Rank: Genius
  14. ddayx10

    66,538

    Master

    0 points yesterday

    Profile
    Rank: Sage
  15. anarki_jimbel

    66,132

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  16. ambience

    63,764

    Master

    0 points yesterday

    Profile
    Rank: Sage
  17. ukerandi

    62,593

    Master

    1,000 points yesterday

    Profile
    Rank: Guru
  18. apeter

    60,772

    Master

    0 points yesterday

    Profile
    Rank: Sage
  19. JamesBurger

    60,305

    Master

    0 points yesterday

    Profile
    Rank: Sage
  20. sedgwick

    52,750

    Master

    1,600 points yesterday

    Profile
    Rank: Genius
  21. emoreau

    50,917

    Master

    0 points yesterday

    Profile
    Rank: Genius
  22. ged325

    50,311

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  23. anuradhay

    49,977

    2,500 points yesterday

    Profile
    Rank: Guru
  24. techChallenger1

    47,638

    0 points yesterday

    Profile
    Rank: Guru
  25. mas_oz2003

    43,540

    0 points yesterday

    Profile
    Rank: Genius

Hall Of Fame