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):
- Adding a new WCF Service item for the first time auto-generates
behaviorsandserviceHostingEnvironmentdeclarations insystem.serviceModel. Noservicedeclaration is generatedâwhich is makes the configuration more maintainable. - Adding a new AJAX-enable WCF Service item generates a
servicedefinition because it needs an explicit endpoint definition with an AJAX-friendly binding and behavior configuration. - Adding a new AJAX-enable WCF Service item after adding a WCF Service item causes the first WCF service to breakâso the idea of trying to get MEX and rest by making a few Visual Studio moves with âsmartâ defaults (without Glenn Blockâs help) is not realistic.
The System Service Model Service Definition
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
- âExposing a WCF Service With Multiple Bindings and EndpointsââKeith Elder: âIn order to configure our service we are going to use the Microsoft Service Configuration Editor. This editor allows us to configure our WCF service and can be launched right from Visual Studio. To launch the editor, right click on the
web.configfile. An option should be in the menu that says âEdit WCF Configurationâ. If it doesnât donât worry, sometimes, Visual Studio doesnât [pick up] this option. A trick is to go to the tools menu in Visual Studio and select the editor from there. After the editor is launched it will then show up in the menu when you right click theweb.configfile.â - âSerialize WCF message in a binary way, and not as a SOAP Messageâ (âOut of the box, the
basicHttpandwsHttpbindings use text encodingâbut you can change that if you want to. ThenetTcpbinding (which is the clear preferred choice behind corporate firewalls) will use binary by default.â) - âMisunderstood: Add Service Referenceâ (describes
configuration91.svcinfoand the other service reference files) - âConsuming WCF REST Services Using jQuery AJAX Callsâ
- âWCF Web HTTP Service Help Pageâ
- âWCF Binding: BasicHttpBinding vs WsHttpBindingâ
- âDifference between BasicHttpBinding and WsHttpBindingâ
- âSimplified Configuration for WCF Servicesâ
- âHow to: Create a Service That Returns Arbitrary Data Using The WCF Web HTTP Programming Modelâ




