WCF service suddenly cannot find binding RRS feed

  • Question

  • I have a small WPF app with one WCF service.  

    I use svcutil.exe to generate the client side code needed to support my services.    I have  been using this process for 10+ years for 100s of services and normally things work as expected.

    Using VS 2019, I was working in the app today and suddenly the app hung a bit, some of the code pages looked like VS was confused about which code pages it was showing, then one of my web service methods had a parameter that I removed several hours ago.  (Everything has been working fine all day up to this point).

    I removed the parameter again, cleaned and rebuilt the solution, ran svcutil.exe again, then tried to run the solution and instantly I get the dreaded error:

    Could not find default endpoint element that references contract 'MainService' in the ServiceModel client configuration section.

    Everything should be perfect but for the life of me I cannot determine why this doesn't work anymore.

    This is from the App.config:

            <binding name="CustomBinding_MainService">
              <binaryMessageEncoding />
              <httpTransport maxReceivedMessageSize = "2147483647" maxBufferSize = "2147483647" />
            </binding >
          <endpoint address="http://localhost:18418/WS/Ap/Main/MainService.svc"
                    binding="customBinding" bindingConfiguration="CustomBinding_MainService"
                    contract="MainService" name="CustomBinding_MainService" />
        <extensions />

    and this is from the web.config:

            <binding name="VelocityService.MainService.customBinding0" closeTimeout="00:11:00" openTimeout="00:11:00" receiveTimeout="00:11:00" sendTimeout="00:11:00">
              <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <httpTransport maxReceivedMessageSize="2147483646" />
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
          <service name="VelocityService.MainService">
            <endpoint address="" binding="customBinding" bindingConfiguration="VelocityService.MainService.customBinding0" contract="VelocityService.MainService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    Any ideas on how to trouble shoot this?

    Thank you.

    Tuesday, July 21, 2020 1:46 AM

All replies

  • Hi moondaddy,

    Thank you for posting here.

    Since your question is related to WCF, I suggest you raise your question in the ASP.NET Forum -> WCF, ASMX and other Web Services.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 21, 2020 3:11 AM
  • First please note that you don't need to keep running svcutil. VS supports refreshing a service endpoint directly from the Service References node. Using that has it refresh the generated code but it shouldn't touch the config file. This will speed things up. Also you should probably never update the service reference and see any changes in the config. If you do see changes in the config then revert those changes.

    Taking a look at your app.config it doesn't look right to me. The endpoint name is `CustomBinding_MainService`. The contract interface it is implementing is `MainService`. Therefore in your app code you would be using the `MainService` interface but the service client would need to be using the endpoint `CustomBinding_MainService`. This is wrong to me for several reasons. Firstly interfaces start with an I so I would expect the interface name to be `IMainService`. This not only follows standard practice but it makes it clear it is an interface and, often, that the `MainService` type provides the base implementation.

    The second issue is that, by default, the service client code should have a default constructor that uses the default endpoint name which should line up with the type name. So if you had a service client called `MainServiceClient` it would use `MainService` endpoint (pulling this from memory so could be off here). It might use a base ctor that lines up with the value in the config but when using svcutil there isn't a config (I believe) so it wouldn't have this info. Add Service Reference will though. 

    So, I believe the issue is just that the default constructor you're likely calling is using the wrong endpoint name. Your config looks wrong to me. The endpoint contract and name are incorrect. Match these up to what the service client expects and your problem should be solved.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, July 21, 2020 1:59 PM