【问题标题】:SoapClient in C# dll called in C++ project : no endpoint found在 C++ 项目中调用 C# dll 中的 SoapClient:找不到端点
【发布时间】:2016-09-20 12:05:04
【问题描述】:

我有一个由 Java 应用程序创建的 Web 服务。我想从 C++ 项目中调用它的服务。我一直在尝试 gsoap 和其他 C++ 代码生成器,但它们都已过时或不受支持。

所以我决定在 C# 中添加一个接口,这意味着我将在 C# 中创建一个 SOAP 客户端,它将调用 Web 服务的每个函数(在 VS2015 中,您只能在 Windows 窗体应用程序中这样做,不知道为什么... )。

然后,我将通过使用robert giesecke 的 nuget UnmanagedExports 将 C# 项目编译为 DLL 来导出这些函数,我将在 C++ 的最终项目中加载该 dll。

但是,当我尝试在 C++ 脚本中调用 web 服务时,我的应用程序崩溃并显示此日志

Unhandled Execption: System.InvalidOperationException : 
Could not find default endpoint element that references contract DockersWS.DockersWS 
in the ServiceModel client configuration section. This might be because no configuration 
file was found in your application or because no endpoint element matching this contract
could be found in the client element
at RawCSSoap\Services references\DockersWS\Reference.cs line 898

DockersWS 是在 C# SOAP 客户端中调用的 Web 服务的名称。 References.cs 中的第 898 行如下所示:

public DockersWSClient() {}

我像这样在 C# 应用程序中创建客户端,直接在我正在导出的函数中。

DockersWS.DockersWSClient client = new DockersWS.DockersWSClient();

当我添加服务参考时,VS2015 生成的 app.config 如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="DockersWSPortBinding" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://nxl35726:8080/DockersWS/DockersWS"
            binding="basicHttpBinding" bindingConfiguration="DockersWSPortBinding"
            contract="DockersWS.DockersWS" name="DockersWSPort" />
    </client>
</system.serviceModel>

WSDL 文件中处理端点的部分如下所示:

<binding name="DockersWSPortBinding" type="tns:DockersWS">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
  <!--bunch of operations-->
</binding>
<service name="DockersWS">
  <port name="DockersWSPort" binding="tns:DockersWSPortBinding">
     <soap:address location="http://nxl35726:8080/DockersWS/DockersWS" /> 
  </port>
</service>

我看到有时还会生成一个 web.config 文件。但我没明白。也许这就是问题所在,但是我该如何生成它呢?

我尝试将 app.config 文件作为资源添加到 C++ 项目,但没有帮助。

所以我的问题是:如何在 C++ 项目中充分使用 SOAP 客户端功能,而不会出现此端点问题?

【问题讨论】:

  • 你如何创建你的肥皂客户端?使用 wsdl.exe?
  • 嗯,VS2015 实际上是我形成的。我关注了tutorial,如您所见,客户端是在步骤 5 中由 VS2015 直接生成的。我尝试使用 wsdl.exe 生成它,但没有成功。你有好的教程吗?
  • 检查此网址msdn.microsoft.com/en-us/library/7h3ystb6(v=vs.100).aspx。但似乎他们已经在 VS2015 中摆脱了 wsdl.exe
  • 确实,该命令在开发人员命令提示符中被识别,但在解析 wsdl 文件时崩溃

标签: c# c++ soap dll endpoint


【解决方案1】:

找到诀窍:

所有这些混乱都源于 C# 项目中的 app.config 没有导出到 DLL 中。所以C++项目没有办法配置它的调用来创建一个Client。

因此,解决方案是将客户端配置硬编码到 C# 函数中,导出此函数并在 C++ 应用程序中调用它。

这里是替换app.config文件的代码

BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
        basicHttpbinding.Name = "DockersWSPortBinding";
        basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
        EndpointAddress endpointAddress = new EndpointAddress("http://nxl35726:8080/DockersWS/DockersWS?wsdl");
        proxyClient = new DockersWS.DockersWSClient(basicHttpbinding, endpointAddress);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 2012-07-06
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    相关资源
    最近更新 更多