WCF终结点错误:找不到默认的终结点元素。

6
这是我的问题。我有一个在服务中使用的客户端,在使用Visual Studio内置的测试主机测试该服务时,所有服务合同都可用。但是,当我尝试测试其中一个服务合同时,Visual Studio会输出以下错误信息:
“找不到默认终结点元素,该元素引用了ServiceModel客户端配置部分中的契约'TestServiceReference.ITestService'。这可能是因为找不到应用程序的配置文件,或者没有与此合同匹配的终结点元素存在于客户端元素中。”
现在,我知道最直接、显而易见的答案是检查我的配置以确保我的终结点是正确的,但是问题在于,它是正确的。我检查了实现客户端的服务的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。我很困惑。你们有什么建议吗?

感谢任何帮助!


你能发布完整的客户端配置吗?可能会出现客户端有两个终结点或者你声明了一个绑定配置但是没有正确使用。 - jtabuloc
3个回答

19

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


这最终成为了解决方案。我需要将一些 app.config 的配置设置镜像到 web.config 中。具体来说,我需要镜像绑定。 - MuffinTheKid
这也正是我的问题。 - Jonathon Cowley-Thom

0

尝试使用以下设置:

客户端配置:

        <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>标记的内容,并添加/更新您的服务引用即可。这将修复客户端配置文件中的设置。


0
对我来说,当我意外地将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#项目。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接