c# - WCF 终结点错误 : Could not find default endpoint element

标签 c# .net wcf wcf-endpoint

所以这是我的问题。我有一个在服务中使用的客户端,当我使用 Visual Studio 中的内置测试主机测试该服务时,所有服务契约(Contract)都可用。但是,当我尝试测试其中一项服务契约(Contract)时,Visual Studio 吐出以下错误

Could not find default endpoint element that references contract 'TestServiceReference.ITestService' 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.

现在,我知道直接而明显的答案是检查我的配置以确保我的端点正确,但就是这样,它是正确的。我检查了实现客户端的服务的 web.config 和客户端的 app.config。两个端点都是正确的(至少我认为是)。

这是 web.config 端点:

<endpoint address="http://testServiceRepo/TestServices/TestService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService"
            contract="TestServiceReference.ITestService"
            name="BasicHttpBinding_ITestService" />

这是 app.config 端点:

<endpoint address="http://testServiceRepo/TestServices/TestService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService"
            contract="TestServiceReference.ITestService"
            name="BasicHttpBinding_ITestService" />

端点完全相同,它们都引用 TestServiceReference.ITestService。所以,我在这里不知所措。你们有什么建议?

感谢您的帮助!

最佳答案

如果您在类库中调用服务并从另一个项目调用类库,则会出现此错误。在这种情况下,您需要将 WS 配置设置包含到主项目 app.config 中(如果它是 winapp)或 web.config(如果它是 Web 应用程序)。你是怎么测试的?您是否尝试过使用 svcutil 创建客户端代理/类,然后测试这些方法。它还会在输出中生成需要的配置,您可以使用配置文件。

关于c# - WCF 终结点错误 : Could not find default endpoint element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31661838/

相关文章:

c# Activator.CreateInstance 不初始化变量

c# - 点网压缩 : Deny removing and updating list of files in protected zip

vb.net - 混合服务和项目引用

wcf - Silverlight 4 安全 LOB 应用程序 - WCF 与 WCF Ria 服务

c# - 如何在Module中使用container.Resolve?

c# - 如何在 VS 2015 RC 中将控制台应用程序(.NET 核心 5)发布为单个 EXE 文件?

.net - 什么是适合我们需求的轻量级 ORM?

mysql - WCF 服务中 SQL 查询的语法错误

c# - ListViewItem 不使用字体

c# - 带有类型参数的通用工厂