【问题标题】:Using class library with WCF service in ASP.NET 5在 ASP.NET 5 中将类库与 WCF 服务一起使用
【发布时间】:2016-01-08 18:05:56
【问题描述】:

在我的项目中,我有一个包含 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 应用程序中那样添加我的绑定?

【问题讨论】:

  • 您实际上不必将绑定添加到配置文件。相反,以编程方式创建它们。
  • 我在解决方案的几个 MVC 项目中使用这个库,并希望使用相同的方法。有可能吗?

标签: c# wcf asp.net-core


【解决方案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

【讨论】:

  • 我在解决方案中有 MVC5 应用程序的配置,但对于 MVC6,我没有 web.config,我想在 IIS Express 上调试和运行时使用相同的服务
【解决方案2】:

我能够通过编程方式配置绑定来运行。感谢@wiktor-zychla 的评论。

var documentService = new DocumentServiceClient(
                                  new BasicHttpBinding(BasicHttpSecurityMode.None),
                                  new EndpointAddress("http://localhost:60205/DocumentService.svc"));

【讨论】:

    猜你喜欢
    • 2011-03-14
    • 2011-03-06
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-28
    • 2011-01-08
    • 1970-01-01
    相关资源
    最近更新 更多