简体   繁体   English

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

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

So here is my problem.所以这是我的问题。 I have a client that is utilized within a service, and when I test said service using the built-in test host in Visual studio, all of the service contracts are available.我有一个在服务中使用的客户端,当我使用 Visual Studio 中的内置测试主机测试所述服务时,所有服务合同都可用。 But, when I try to test one of the service contracts, Visual studio spits out the following error但是,当我尝试测试其中一个服务合同时,Visual Studio 会出现以下错误

Could not find default endpoint element that references contract 'TestServiceReference.ITestService' in the ServiceModel client configuration section.在 ServiceModel 客户端配置部分中找不到引用合同“TestServiceReference.ITestService”的默认端点元素。 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.这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

Now, I know the immediate and obvious answer is to check my config to make sure that my endpoint is correct, but that is the thing, it is correct.现在,我知道直接而明显的答案是检查我的配置以确保我的端点是正确的,但就是这样,它是正确的。 I checked both the web.config for the service implementing the client, and the app.config for the client.我检查了实现客户端的服务的 web.config 和客户端的 app.config。 Both endpoints are correct(at least I think they are).两个端点都是正确的(至少我认为它们是)。

Here is the web.config endpoint:这是 web.config 端点:

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

Here is the app.config endpoint:这是 app.config 端点:

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

The endpoints are the exactly the same, and they both reference TestServiceReference.ITestService.端点完全相同,它们都引用 TestServiceReference.ITestService。 So, I am at a loss here.所以,我在这里不知所措。 What would you guys suggest?大家有什么建议?

Thanks for any help!谢谢你的帮助!

This error can arise if you are calling the service in a class library and calling the class library from another project.如果您在类库中调用服务并从另一个项目调用类库,则可能会出现此错误。 In this case you will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app.在这种情况下,您需要将 WS 配置设置包含到主项目 app.config(如果它是一个 winapp)或 web.config(如果它是一个 Web 应用程序)。 how you are testing it ?你是如何测试的? Did you tried to create client proxy/class using svcutil and then test these methods.您是否尝试使用 svcutil 创建客户端代理/类,然后测试这些方法。 it also generates require configuration in output,config file which you can use.它还在输出中生成需要配置,您可以使用配置文件。

Try settings like this:尝试这样的设置:

client config:客户端配置:

        <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>

server config:服务器配置:

        <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>

EDIT编辑

Note: Actually if you are using service reference (generated proxy) it is enough to fix the settings of service, delete the content of <system.serviceModel> tag in client, and add/update your service reference.注意:实际上,如果您使用服务引用(生成的代理),只需修复服务的设置,删除客户端中<system.serviceModel>标记的内容,并添加/更新您的服务引用。 It will fix up your settings in the client's config file.它将在客户端的配置文件中修复您的设置。

For me this exact issue happened when I accidentally 'fixed' the WCF endpoint as对我来说,当我不小心将 WCF 端点“修复”为

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

instead of代替

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

(notice the lowercase 's' in the word TestService first address example) (注意TestService首地址示例中的小写's')

This was for ac# project这是针对 ac# 项目的

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

相关问题 WCF错误 - 找不到引用合同的默认端点元素 - WCF Error - Could not find default endpoint element that references contract 在WCF客户端中找不到默认端点元素… - Could not find default endpoint element … in WCF Client 找不到默认端点元素错误 - Could not find default endpoint element error 在Allscripts中找不到默认端点元素错误 - Could not find default endpoint element error in Allscripts 找不到引用合同的默认端点元素 - 托管wcf - Could not find default endpoint element that references contract - Hosting wcf 使用WCF服务 - 找不到默认端点元素 - Consume WCF Service - Could not find default endpoint element 在WCF中找不到引用合同的默认终结点元素 - Could not find default endpoint element that references contract in WCF WCF运行时异常“找不到引用的默认终结点元素……” - WCF Runtime Exception “Could not find default endpoint element that references…” WCF 安装程序 class - 找不到引用合同的默认端点元素 - WCF installer class - Could not find default endpoint element that references contract 在 SQL 中创建一个调用 WCF 服务器的 DLL 错误:找不到引用合同的默认端点元素 - Making a DLL in SQL which call WCF Server Error : Could not find default endpoint element that references contract
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM