繁体   English   中英

如何将服务引用添加到C#库?

[英]How do I add a service reference to a C# library?

如果我将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 ++,使此应用程序运行的最佳方法是什么?

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

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

    using (ReferenceServiceClient client = new ReferenceServiceClient(binding, address))
    {
        ...
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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