简体   繁体   中英

SoapClient in C# dll called in C++ project : no endpoint found

I have a webservice, created by a Java application. I want to call its services from a C++ project. I've been trying gsoap and other C++ code generators, but they're all out of date or unsupported.

So I decided to add an interface in C#, meaning that I will create a SOAP client in C# that will call each function of the webservice (in VS2015, you can only do that in Windows Form Application, dunno why ...).

Then I will export these functions by compiling the C# project as a DLL with the nuget UnmanagedExports of robert giesecke , dll which I will load in my end project in C++.

However, when I try to call the webservice in the C++ script, my app crashes with this log

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 is the name of the webservice called in the C# SOAP Client. The line 898 from References.cs looks like this :

public DockersWSClient() {}

I create the client in the C# app like this, directly in the function I'm exporting.

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

My app.config generated by VS2015 when I added the Service Reference looks like this:

<?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>

And the part of the WSDL file dealing with endpoint looks like this:

<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>

I've seen that sometimes a web.config file is generated also. But I didn't get it. Maybe that's the issue, but how can I generated it, then ?

I tried to add the app.config file to the C++ project as a Resource, but it didn't help.

So my question is : how can I fully use the SOAP client functions in the C++ project, without having this endpoint issue?

FOUND THE TRICK:

All this mess comes from the fact the app.config in the C# project is not exported in the DLL. So the C++ project has no way to configure its call to create a Client.

Therefore, the solution is to hard-code the client configuration in a C# function, export this function and call it in your C++ application.

Here is the code to replace the app.config file

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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM