简体   繁体   中英

WCF Service consumed in Class Library, when accessed by other Class Library gives “Could not find endpoint element…” Error

I have a solution that has three projects:

  1. WPF Application
  2. Class Library
  3. NUnit Testing Class Library

The class library has service references that generated the following in app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      etc, etc
    </bindings>
    <client>
      <endpoint address="http://localhost:8088/myService                
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_myService"
          contract="Namespace.myService" name="BasicHttpBinding_myService" />
    </client>
  </system.serviceModel>
</configuration>

The class library has functions that access these services, retrieve data and package them for use in the WPF application. After copying the app.config file from the Class Library to the WPF Application project, the WPF app can use the data access functions from the Class Library without any issues (before copying app.config , I got a "Could not find default endpoint" error message when trying to call those methods from the WPF app).

When trying to call the very same functions in my testing library, and running them from NUnit, I get an error of type "could not find the default endpoint element that references contract in the servicemodel client configuration section". Other posts had recommended making sure that the app.config file was in the testing project - but after I did that, it still gave the same error message. How can I make this work?

The problem was not with the setup of the project - it was with the setup of the NUnit project.

When I set up the NUnit project, I used the Project > Add Assemblies toolbar option to add my assembly to the NUnit project (using the NUnit GUI). At this point, NUnit was looking for the config file in the same directory that I saved the NUnit project settings. This led to the error where the config settings could not be found when needed.

I solved this by going to Project > Edit in the NUnit GUI, and then setting the Project Base to the \\bin directory of the testing project, and the Configuration File Name to the file name of the config file for the project. After this, NUnit was now able to find the proper config file when running my tests, solving the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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