Could not find default endpoint element that references contract

前端 未结 7 1269
傲寒
傲寒 2020-12-09 11:13

I know this has been beaten to death, but I cannot get this to work as it should. I have a WCF service with several contracts. They all work fine when calling them directly

相关标签:
7条回答
  • 2020-12-09 11:34

    Adding binding and client values from app.config to default web.config resolved my issue.

    0 讨论(0)
  • 2020-12-09 11:37

    If we have layered architecture make sure to

    1) add app.config in "all projects"
    2) add service config details in all app.config
    3) run the project
    
    0 讨论(0)
  • 2020-12-09 11:40

    Actually the trick to this one was to use the svcutil.exe to create the proxy. I had been trying to create the proxy through Visual Studio "Add Service" wizard. Once I did that, the configuration was a breeze.

    SvcUtil.exe

    0 讨论(0)
  • 2020-12-09 11:43

    When it comes down to WCF, it typically requires the configuration to be defined within the config file of the executable that calls it.

    Thus, if you are unfortunate enough to having to call a WCF DLL from within a VB6 program (as may be the case when using a COM-interop .NET module, for example), and you need to debug the VB6 program, then you will need to create a VB6.exe.config file in the directory where VB6.exe is located.

    Failing to do the above may cause a "Could not find default endpoint element that references contract".

    As a workaround, one can load the dll's config file at runtime and then call the constructor of the used Service with a Binding and an EndpointAddress as parameters (obtained from the dll's config).

    0 讨论(0)
  • 2020-12-09 11:46

    If your project is referencing a library and trying to use the WCF functions from the functions of that library, then you can try copying the client endpoint from the project config file to the dll's config file. Some thing like this happened to me a while ago as the library that I referenced in the project would not use the project config file (in which the client end point was configured since the service was being referenced there) but its own so the result was the system could not find the endpoint configurations.

    0 讨论(0)
  • 2020-12-09 11:49

    The error indicates that you don't have an endpoint defined in the client configuration section. When you add the service reference to your project it should create the client section for you. If not then in the web.config for your app within the system.serviceModel section add the following

    <client>
      <endpoint 
          name="CompanyWcfService_webhttpBinding"
          address="http://merlin.com/CompanyServices/CompanyWcfService.svc" 
          binding="webHttpBinding" 
          contract="CompanyWcfServices.ICompanyWcfService" 
          behaviorConfiguration="webHttpEndpointBehavior"
      />
    </client>
    
    0 讨论(0)
提交回复
热议问题