VB6 调用 WCF: 找不到端点元素

VB6 calling WCF: Could not find endpoint element

我有一个旧版 VB6 应用程序需要调用 .Net .dll 才能调用 WCF Web 服务。

起初,我收到了这条烦人的消息:

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.

我遵循了这个 link - Using app.config with Interop Controls - 它帮助我让我的 VB6 测试 exe 工作:

1) 从网络测试客户端

复制了一个 app.config

2) 重命名为MyVb6Test.exe.config(与VB6 exe同名)

到目前为止,还不错。

当前问题:

实际的客户端是一个 VB6.exe,它调用一个 VB6 .dll,它调用 .Net/COM-aware .dll:

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

即使我创建了 MyLegacyVb6App.exe.config - 与工作 VB6 测试完全一样 - 我仍然得到 "Could not find endpoint element with name 'DocumentMetadataPortSOAP12'..."

这是 "MyNewDotNet.dll" 中的 .Net 代码:

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

问:我真的需要 "app.config" 有什么理由吗?有什么办法可以直接在我的 C# 代码中 "hard code" 需要什么吗?

问:我的场景还有哪些其他选择:VB6 exe -> VB6 .dll -> .Net/Interop .dll => WCF???

非常感谢您!

毕竟我能够使用 App.config 解决问题。

问题:

因为我的 .Net .dll 是从一个从 VB6 .exe 调用的 VB6/COM .dll 调用的(天知道中间有多少 VB6/COM 组件)... .Net碰巧在 UNEXPECTED 地方寻找 app.config - NOT 在与 VB6 .exe 本身相同的目录中(?! ?)

解决方案:

我使用 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile tp 获取 .Net 寻找的实际位置 app.config:

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