Search code examples
c#.netwcfapp-configservice-reference

Why is the <system.serviceModel> section missing from app.config?


I'm trying to consume a WCF service. I added a Service Reference, and now I'm trying to call it:

BusStopServiceBinding.BusStopPortTypeClient client = new BusStopServiceBinding.BusStopPortTypeClient();

However, I'm getting this error:

Could not find default endpoint element that references contract 'BusStopServiceBinding.BusStopPortType' 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.

My app.config file looks like this:

<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>

No serviceModel section, as you can see. Should I add it manually, and if so, what should I put in it?


Solution

  • This section is for WCF configuration. In the Tools section in visual studio you have a "WCF Service configuration editor" which help you to create this section. If you don't have this section you must configure it in code, but it is not the best practise. In this section you have to put the end point, the security settings, bindings, the wcf contract,...