Click here to Skip to main content
15,868,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am attempting to consume a working C# WCF service (RCWindsSvc) via a .Net 4.5 C# MVC4 WebAPI (RCWindsExtSvc). I am receiving the following run-time error when calling the WCF service from the WebAPI:

'Could not find endpoint element with name 'RCWindsSvcEndpoint' and contract 'RCWindsSvc.IService1' in the ServiceModel client configuration section.
This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.'

The system.serviceModel from the web.config in the WCF Service is:

XML
 <system.serviceModel>
  <services>
    <service name="RCWindsSvc.Service1" behaviorConfiguration="RCWindsSvc.Service1Behavior">
      <endpoint address="http://localhost:15021/RCWinds.svc"
          binding="webHttpBinding"
          contract="RCWindsSvc.IService1"
          behaviorConfiguration="ServiceAspNetAjaxBehavior"
          name="RCWindsSvcEndpoint"/>
      <!-- behaviorConfiguration="WebBehaviour" /> -->
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="RCWindsSvc.Service1Behavior">
        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <!-- <behavior name="webBehaviour">
        <webHttp/>
      </behavior>-->
      <behavior name="ServiceAspNetAjaxBehavior">
        <enableWebScript/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>


I am using ConfigurationChannelFactory in the WebAPI code to retrieve the WCF configuration data, and the following is the code from the WebAPI Controller:

C#
public String[] GetStationNames()
           {
               ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
               fileMap.ExeConfigFilename = "web.config";
               Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

               ConfigurationChannelFactory<RCWindsSvc.IService1> factory1 = new
                   ConfigurationChannelFactory<RCWindsSvc.IService1>("RCWindsSvcEndpoint", newConfiguration, new EndpointAddress("http://localhost:15021/RcWinds.svc"));
               RCWindsSvc.IService1 client1 = factory1.CreateChannel();

               IEnumerable<string> stationNames = client1.GetStationNames();
               return stationNames.ToArray();

           }


This seems to be a somwhat common issue and I have explored a number of suggested solutions to no avail. Any assistance with this is greatly appreciated.
Posted
Comments
Kumarbs 25-Aug-14 8:51am    
Make sure the endpoint is available in the webAPI web.config file.

Thank you, Kumarbs. I am still receiving the error message with the following config and code:

My new WebAPI config is:

XML
<system.servicemodel>
   <client>
     <endpoint name="RCWindsSvc.Service1">
               contract="RCWindsSvc.IService1"
               binding="webHttpBinding"
               address="http://localhost:15021/RCWinds.svc">
     </endpoint>
   </client></system.servicemodel>


Code snippet:

C#
public class RCWindsExtSvcController : ApiController
    {

        public String[] GetStationNames()
            {
                ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
                fileMap.ExeConfigFilename = "web.config";
                Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

                ConfigurationChannelFactory<rcwindssvc.iservice1> factory1 = new
                    ConfigurationChannelFactory<rcwindssvc.iservice1>("RCWindsSvc.Service1", newConfiguration, new EndpointAddress("http://localhost:15021/RCWinds.svc"));
                RCWindsSvc.IService1 client1 = factory1.CreateChannel();

                IEnumerable<string> stationNames = client1.GetStationNames();
                return stationNames.ToArray();
            }
    }</string></rcwindssvc.iservice1></rcwindssvc.iservice1>


Thank you.
 
Share this answer
 
I was able to resolve this by by doing two things: 1) remove the ConfigurationChannelFactory code and 2)I use the Service Configuration Editor utility (SvcConfigEditor.exe) to properly build the client section on the WebApi side. When complete, I was able to move past the error. I am receiving another, different error which I will post in a new thread.
Thanks to everyone. DAFuller
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900