Search code examples
c#wcfvb6interop

VB6 calling WCF: Could not find endpoint element


I have a legacy VB6 app that needs to call .Net .dll in order to invoke a WCF web service.

At first, I got this annoying message:

Could not find endpoint element with name 'DocumentMetadataPortSOAP12' and contract 'CODSRef.DocumentMetadataType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

I followed this link - Using app.config with Interop Controls - and it helped me get my VB6 test exe working:

  1. Copied an app.config from a net test client

  2. Renamed it MyVb6Test.exe.config (the same name as the VB6 exe).

So far, so good.

CURRENT PROBLEM:

The actual client is a VB6.exe that calls a VB6 .dll, which calls the .Net/COM-aware .dll:

  MyLegacyVb6App.exe
    +-> MyNewVB6plugin.dll
          +-> MyNewdotNet.dll
                +-> WCF

Even though I created MyLegacyVb6App.exe.config - exactly like the working VB6 test - I'm still getting "Could not find endpoint element with name 'DocumentMetadataPortSOAP12'..."

Here's the .Net code in "MyNewDotNet.dll":

DocNotificationRequesttype wsRequest = new DocNotificationRequesttype();
DocumentMetadataTypeClient wsClient =  new DocumentMetadataTypeClient("DocumentMetadataPortSOAP12",  m_wsUrl);
DocNotificationResponsetype wsResponse = wsClient.DocNotification(wsRequest);

Is there any reason I actually need an "app.config"? Is there any way I can "hard code" whatever it needs directly in my C# code?

What other alternatives do I have for my scenario: VB6 exe -> VB6 .dll -> .Net/Interop .dll => WCF?


Solution

  • I was able to resolve the problem by using an App.config after all.

    PROBLEM:

    Because my .Net .dll was being invoked from a VB6/COM .dll called from a VB6 .exe (with gosh knows how many VB6/COM components in the middle) ... .Net happened to be looking for the app.config in an UNEXPECTED place - NOT in thw same directory as the VB6 .exe itself (?!?)

    SOLUTION:

    I used AppDomain.CurrentDomain.SetupInformation.ConfigurationFile tp get the actual location where .Net was looking for app.config:

    LogMsg(">>AppConfigFile=" + AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);