One WCF Service for Rest and Binary

икони на светци

The sweet spot of the moment is standing in a WCF design that tries to stay with one service contract per tiny application (concern). The motivation to do this is for ease of web.config maintenance where there will be one service declaration in the collection of services in system.serviceModel.

The desire for one service definition leads (me) to learning how to build a service contract that supports binaryMessageEncoding and text-based “rest” WebGet or WebInvoke. This desire is reinforced by the following observations (seen in Visual Studio):

Here is that single service declaration promised earlier:<services> <service name="Songhay.Web.HostRoot.Services.WcfServiceOne" behaviorConfiguration="mexServiceBehavior"> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <endpoint address="" binding="customBinding" bindingConfiguration="customHttpBinding" contract="Songhay.Web.HostRoot.Services.IWcfServiceOne" /> <endpoint address="json" behaviorConfiguration="ajaxBehavior" binding="webHttpBinding" contract="Songhay.Web.HostRoot.Services.IWcfServiceOne" /> </service> </services>The customHttpBinding and ajaxBehavior most distinguish this little design. Respectively, we have:<bindings> <customBinding> <binding name="customHttpBinding"> <binaryMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings>and<endpointBehaviors> <behavior name="ajaxBehavior"> <enableWebScript /> <webHttp helpEnabled="true"/> </behavior> </endpointBehaviors>Also, notice that the customBinding and webHttpBinding are not sharing the same path such that http://localhost/MyService.svc/ would be for binary transport and http://localhost/MyService.svc/json/ would be for the AJAX behavior.

Selected Resources

rasx()