在我的项目中,我有一个包含WCF服务连接的类库。
在旧的ASP.NET MVC中,为了使用服务方法,我只需要在web.config中添加绑定,它就能正常工作。
我现在遇到的问题是,当我在ASP.NET5中调用Web服务时,我得到了这个例外:
InvalidOperationException: Could not find default endpoint element that references contract 'xxx' 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.
有没有一种方法可以像我在旧的MVC应用程序中那样添加我的绑定?
答案 0 :(得分:1)
我正在使用MVC应用程序中的以下配置。使用添加服务引用对话框添加对WCF服务的引用时。客户端部分将添加到web.config中的System.ServiceModel部分。它应该根据你得到的错误指定一个似乎缺少的端点。
希望这有帮助
<client>
<endpoint address="http://address.to.your.service.com:8080/V3/ConfigService.svc"
binding="basicHttpBinding"
bindingConfiguration="ConfigService.V3.ConfigHttpServiceBinding"
contract="ConfigService.IConfigService"
name="ConfigService.V3.ConfigHttpService"/>
</client
答案 1 :(得分:0)
我能够通过编程配置绑定来运行。感谢@ wiktor-zychla评论。
var documentService = new DocumentServiceClient(
new BasicHttpBinding(BasicHttpSecurityMode.None),
new EndpointAddress("http://localhost:60205/DocumentService.svc"));