WCF Tip #102: Behavior configuration for SOAP and REST together in single WCF Service.

WCF REST provides flexiblity to transport data over http and surely should be preffered if data is required to be accessed from applications build in different technologies. There are times when this is not possible or when all the involed web service consumers or service clients are build on .Net technology, chances are they may prefer using SOAP over REST then REST and SOAP both endpoints need to coexists in a single service. This series would provide provide tips about combining SOAP with REST in single WCF Service.

I have compared how Behaviors would look for just SOAP VS SOAP+REST service.

Behavior defines how the endpoint interacts with clients. Attributes like security, concurrency, caching, logging, etc are part of service behavior. Behaviors describe the client what the service will be.Eventhough behaviors can be added in three different ways like code, configuration and Attributes, I will use configuration for this example. Below is a comparison of how your SOAP vs SOAP+REST behaviors would look like in configuration.

SOAP:

 <behaviors>
 <serviceBehaviors>
 <behavior name="SoapBehave">
 <serviceMetadata httpGetEnabled="true" />
 <serviceDebug includeExceptionDetailInFaults="false" />
 <serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="50" maxConcurrentInstances="50" />
 <dataContractSerializer maxItemsInObjectGraph="2147483647" />
 </behavior>
 </serviceBehaviors>
 </behaviors>

SOAP+REST:

<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="internal">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="50" maxConcurrentInstances="50" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>