繁体   English   中英

WCF 端点错误:找不到默认端点元素

[英]WCF Endpoint Error: Could not find default endpoint element

所以这是我的问题。 我有一个在服务中使用的客户端,当我使用 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。 所以,我在这里不知所措。 大家有什么建议?

谢谢你的帮助!

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

尝试这样的设置:

客户端配置:

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

对我来说,当我不小心将 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')

这是针对 ac# 项目的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM