Example WCF system.serviceModel web.config sections

This post is to illustrate an example system.serviceModel section in a web.config for WCF .NET 3.5. The system.serviceModel section of your web.config allows you to set security, bindings, endpoints, and behaviors. There is an almost overwhelming number of configuration items you can choose, particularly if you are trying to set up security. Sometimes it is useful to have a reference to use, so I’m hoping this post will help people fix their own web.config issues.

This service is exposed via SOAP, REST and metadata and illustrates some basic settings to use for the system.serviceModel entry.


<!– use the bindings section when you are building a client to connect to a web service, not when you are creating the service –>
  <bindings />
<!– use the client section when you are building a client to connect to a web service, not when you are creating the service –>
  <client />
<!– the services section allows you to define WCF services –>


<!– this service definition is a basic WCF service. Full stops have been added for readability –>
   <service name=”my.service” behaviorConfiguration=”my.behavior.configuration” >
        <!– SOAP endpoint –>


This exposes your service via SOAP

The contract element must match your service contract [ServiceContract] interface

The binding defines the type of service as a WCF service which supports transactions, reliable services, and so on. basicHttpBinding is another common binding to use here.

    <endpoint address=”” binding=”wsHttpBinding” contract=”my.IContract”>

        <!– REST endpoint –>


This exposes your service via REST – see the behavior configuration for more info – note the different binding type of webHttpBinding. This is new in WCF with .NET 3.5SP1, and specifies the REST interface.

Note the use of the “address” element. This is needed to differentiate itself from the SOAP binding above, so SOAP requests would be accessed via (for example) http://server.local/my.service/ and REST requests would use http://server.local/my.service/rest/ i.e. the address element is appended to the service url. If you have the address elements the same for REST and SOAP, WCF will throw a config error.

        <endpoint address=”rest” binding=”webHttpBinding” contract=”my.IContract” behaviorConfiguration=”Endpoints.RESTBehavior”>

        <!– mex endpoint –>

<!– metadata information –>
        <endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange”/>
        <!– WCF Service Behaviors –>
    <behavior name=”my.behavior.configuration”>
          <serviceThrottling maxConcurrentSessions=”100″/>
     <!– 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=”true”/>
      <!– WCF Endpoint Behaviors –>
        <behavior name=”Endpoints.RESTBehavior”>



One Response to “Example WCF system.serviceModel web.config sections”

  1. artcoding Says:

    I have fixed the problem by adding a default binding under basicHTTPBinding, just like in http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d5b7ac03-70f8-4366-b055-c177c61f4dec/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: