WCF Endpoint Error: Could not find default endpoint element

WCF Endpoint Error: Could not find default endpoint element

所以这是我的问题。我有一个在服务中使用的客户端,当我使用 Visual studio 中的内置测试主机测试所述服务时,所有服务合同都可用。但是,当我尝试测试其中一个服务合同时,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。所以,我在这里不知所措。你们有什么建议?

感谢您的帮助!

试试这样的设置:

客户端配置:

        <basicHttpBinding>
            <binding name="BasicHttpBinding_ITestService" />
        </basicHttpBinding>

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

服务器配置:

        <basicHttpBinding>
            <binding name="BasicHttpBinding_ITestService" />
        </basicHttpBinding>

        <behaviors>
          <serviceBehaviors>
            <behavior name="testBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>

        <services>
            <service behaviorConfiguration="testBehavior"  name="TestServiceReference.TestService">
                <endpoint
                          address=""
                          binding="basicHttpBinding"
                          bindingConfiguration="BasicHttpBinding_ITestService"
                          contract="TestServiceReference.ITestService" 
                          name="BasicHttpBinding_ITestService" />
            </service>
        </services>

编辑

注意:实际上,如果您使用服务引用(生成的代理),只需修复服务设置,删除客户端中 <system.serviceModel> 标记的内容,以及 add/update 您的服务引用.它将修复您在客户端配置文件中的设置。

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

对我来说,这个确切的问题发生在我不小心 'fixed' WCF 端点作为

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

而不是

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

(注意单词TestService首地址示例中的小写's')

这是一个 c# 项目