0

如果我将 Web 服务引用添加到 C# 应用程序,那么我可以创建客户端类的实例并毫无问题地调用该服务。但是,如果我对托管 C++ 库调用的 C# 库执行相同的操作,则在尝试创建客户端时会收到以下错误消息:

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.

我检查了 app.config 并且端点条目肯定在客户端部分,所以我假设问题是 app.config 本身没有被引用,因为它在库中。请记住,调用应用程序是托管 C++,什么是让它工作的最佳方法?

4

1 回答 1

1

如果您不打算更改端点,则可以在代码中定义端点:

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

    using (ReferenceServiceClient client = new ReferenceServiceClient(binding, address))
    {
        ...
    }
于 2013-10-09T01:12:19.967 回答