2

I have a WCF service that is running on IIS 8.5. I consumed and Tested the service in a Windows forms project and in a console application project and works fine! But I am not able to consume the web service from a class library project in Visual Studio 2013.

Could not find default endpoint element that references contract 'bindSignalR.bindSinalRService' 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 contract could be found in the client element.

I looked to the configuration files of the Windows Forms Project (that works) and the Class Library Project but I can’t find the difference. What am I doing wrong?

The web.Config of the service is:

<configuration>
    <system.web>
      <compilation targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
                   <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <customBinding>
                <binding name="bindSignalRService.Web.bindSinalRService.customBinding0">
                    <binaryMessageEncoding />
                    <httpTransport />
                </binding>
                               </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
        <services>
            <service name="bindSignalRService.Web.bindSinalRService">
                <endpoint address="" binding="customBinding" bindingConfiguration="bindSignalRService.Web.bindSinalRService.customBinding0"
                    contract="bindSignalRService.Web.bindSinalRService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
</configuration>

The app.config in the Windows form (this one works fine!) app:

<configuration>
    <configSections>
    </configSections>
    <system.serviceModel>
        <bindings>
            <customBinding>
                                   <binding name="CustomBinding_bindSinalRService">
                    <binaryMessageEncoding />
                    <httpTransport />
                </binding>
            </customBinding>
        </bindings>
        <client>
          <endpoint address="http://slascvm042:49904/bindSinalRService.svc"
                binding="customBinding" bindingConfiguration="CustomBinding_bindSinalRService"
                contract="bindNewEventService.bindSinalRService" name="CustomBinding_bindSinalRService" />

        </client>
    </system.serviceModel>
</configuration>

But when I try to consume the WCF service in a Class Library Application I got the error: Could not find default endpoint element that references contract 'bindSignalR.bindSinalRService' 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 contract could be found in the client element.

Daniel Meza
  • 41
  • 1
  • 5
  • The error that I am getting is the one in Bold and in the center. – Daniel Meza Jan 27 '15 at 18:28
  • Under what circumstances do you get that error. I believe you mean you got an exception. Please post the complete exception, including stack trace and any inner exceptions. The simple way to do this, for troubleshooting purposes, is to catch the exception, then post the results of `ex.ToString()`. – John Saunders Jan 27 '15 at 18:39
  • In what process are you hosting the Class Library? Looks like the config of the app that hosts your library has not been updated with the config above. – Rich Turner Jan 27 '15 at 20:43
  • System.InvalidOperationException: Could not find endpoint element with name 'Hola1' and contract 'bindSignalRService.Web.bindSinalRService' 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. – Daniel Meza Jan 27 '15 at 20:43

1 Answers1

2

Solved: Thanks for trying to help me. I was having really hard time with this (many and many hours invested).

When you consume a Web service in a library application (wherever you going to use your library), you have to copy the endpoint and the binding section of the app.config file from your library to the (web/app).config in the proyect that you want to use your LIBRARY!!! (Please correct me if something is wrong).

In my case i copied:

<system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="bind">
                <binaryMessageEncoding />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:49904/bindSinalRService.svc"
            binding="customBinding" bindingConfiguration="bind" contract="bindSignalRService.Web.bindSinalRService"
            name="myEnpointName" />
    </client>
</system.serviceModel>
Daniel Meza
  • 41
  • 1
  • 5
  • 1
    In fact, this is always true for a class library. _Whatever_ is placed in the app.config of the class library will need to be moved to the app.config or web.config of the consuming application. It has been this way since Day 1. Consider that there may be more than one consumer of the library, and that any configuration specific to the library may be different for each consumer. – John Saunders Jan 27 '15 at 22:03