如果我向C#应用程序添加Web服务引用,那么我可以创建客户端类的实例并毫无问题地调用服务。但是,如果我对托管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 ++的,最好的方法是什么?
答案 0 :(得分:1)
如果您不打算更改端点,则可以在代码中定义端点:
EndpointAddress address = new EndpointAddress("http://serviceEndpointUri");
BasicHttpBinding binding = new BasicHttpBinding();
using (ReferenceServiceClient client = new ReferenceServiceClient(binding, address))
{
...
}