Question

If I add a web service reference to a C# application then I can create an instance of the client class and call the service without any problems. However, if I do the same thing to a C# library that's being called by a managed C++ library I get the following error message when I try to create the client:

Could not find default endpoint element that references contract 'ServiceReference1.IMyService' 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 contract could be found in the client element.

I've checked the app.config and the endpoint entry is definitely in the client section, so I'm assuming the problem is that the app.config itself isn't being referred to because it's in a library. Keeping in mind that the calling application is managed C++, what's the best way to get this working?

Était-ce utile?

La solution

You could define your endpoint in code, if you do not plan on changing the endpoint:

    EndpointAddress address = new EndpointAddress("http://serviceEndpointUri");
    BasicHttpBinding binding = new BasicHttpBinding();

    using (ReferenceServiceClient client = new ReferenceServiceClient(binding, address))
    {
        ...
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top