Could not find default endpoint element that references contract
I received this error while adding a reference to a WCF service in a windows form application with multiple projects.
Error: Could not find default endpoint element that references contract '*' 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.
After hours of troubleshooting, I should have read the message more closely. This is basically saying the application cannot contact this service. It gives 2 possible reasons why. One is that you did not include a configuration file which would be the app.config. By default this created by the windows project templates. So it was there. The second reason is that there is not endpoint element in this XML file (app.config).
That was my problem. When you add a reference to a project using VS it will modify the app.config file and place this element in it automatically. As it turns out, when you have multiple projects in a solution and you add a reference to a project, VS will modify the app.config file of the project you are working in. This may not be where the element needs to be placed if your solution has a different MAIN project or different startup project. You will have to manually add this element to the app.config file that is the MAIN file for the solution.
Copy the following elements to the MAIN app.config file for your solution and you will be back on track.
Good Luck
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICFR" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/SVC/CFR.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICFR"
contract="CFR_WCF.ICFR" name="WSHttpBinding_ICFR">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Contact Us