Building a Custom Binding with DCS Binding Elements
The Microsoft.ConnectedIndustry.ServiceModel.Application.Bindings.ExtendedHttpBinding class in the Microsoft.ConnectedIndustry.ServiceModel.Application assembly is a custom Windows Communication Foundation (WCF) binding that provides support for the custom protocol channels implemented by DCS. Typically, DCS services use a binding built from the ExtendedHttpBinding class to listen for client requests. You can reference this class in a configuration file by specifying the binding name extendedHttpBinding. The following sample shows a typical <serviceFactory> configuration that uses the extendedHttpBinding binding.
<cis.serviceModel>
<serviceFactory>
<httpBaseAddress dnsAlias="localhost"/>
<defaultServiceConfiguration serviceBehavior="DCSBehavior">
<defaultEndpoint behaviorConfiguration="enableTracing">
<defaultSimplexBinding binding="extendedHttpBinding" bindingConfiguration="simplex"/>
<defaultDuplexBinding binding="extendedHttpBinding" bindingConfiguration="duplex"/>
</defaultEndpoint>
</defaultServiceConfiguration>
</serviceFactory>
...
</cis.serviceModel>
An operation in a DCS service that implements the client-initiated request/response or one-way messaging patterns uses the <defaultSimplexBinding> binding. An operation that initiates messaging with a client application by using a callback contract uses the <defaultDuplexBinding> binding.
Client applications that use the Discovery Service to connect to a DCS service do not contain a binding configuration for communicating with that service. Instead, they use the defaultSimplexBinding configuration of the defaultEndpoint specified in the service configuration file to configure the client binding dynamically. However, a service can expose multiple endpoints and can configure a different binding configuration for each endpoint, tuned to the requirements of the operations exposed through that endpoint. For example, a service that implements operations that return binary large object (BLOB) data might configure an additional endpoint that specifies the MTOM encoding. A client application can use a custom endpoint selector to determine the most appropriate endpoint to use for an operation. For more information, see Building a Custom Endpoint Selector.
Configuring an extendedHttpBinding Binding
The following table describes the configuration properties that the extendedHttpBinding binding exposes.
Configuration Property |
Description |
---|---|
transactionFlow |
This is a Boolean property that specifies whether transactions should flow between the client application and the service. |
contextFlow |
This is a Boolean property that specifies whether context information should flow between the client application and the service. |
isComposite |
This is a Boolean property. If it is set to true, then Microsoft.ConnectedIndustry.ServiceModel.ProtocolChannels.CorrelatorBindingElement and System.ServiceModel.Channels.OneWayBindingElement binding elements are added to the channel stack created for the binding. |
clientBaseAddress |
This property is used by duplex bindings. It specifies a URI that contains the base address of the client application. |
hostNameComparisonMode |
This property indicates how the hostname is used to reach the service when matching the hostname against the URI of a message. Valid values for this property are: |
proxyAddress |
This property specifies the URI of a proxy to use for HTTP requests. |
bypassProxyOnLocal |
This is a Boolean property that indicates whether the binding should ignore proxies for local addresses. The default value, false, always uses a proxy if one exists. Proxies are always ignored for service addresses that begin with https://localhost. |
useDefaultWebProxy |
This is a Boolean property that indicates whether the binding should use machine-wide proxy settings or user-specific proxy settings. The default value, true, specifies that the binding uses machine-wide proxy settings. |
You can customize an extendedHttpBinding binding by using the <bindings> section of <system.ServiceModel> in the service configuration file. The default configuration for the simplex and duplex bindings resembles the following example.
<system.serviceModel>
...
<bindings>
<extendedHttpBinding>
<binding name="simplex" />
<binding name="duplex" isComposite="true" />
</extendedHttpBinding>
...
</bindings>
...
</system.serviceModel>
DCS Binding Elements and Binding Element Extension Classes
The ExtendedHttpBinding class constructs a binding by composing a number of custom channels into a channel stack. These custom channels are also provided with DCS. You can compose a customized DCS binding by specify a selected subset of the appropriate binding elements for each of the channels. The following table summarizes these binding elements and the corresponding binding extension elements that a service uses to instantiate them. The binding extension element classes all extend the WCF BindingElementExtensionElement class. For more information, see BindingElementExtensionElement Class.
Binding Element |
Description |
Extension Element |
---|---|---|
ExtendedEncodingBindingElement |
Provides support for the DCS encoding policy. You can encode messages as text or you can use the Message Transmission Optimization Mechanism (MTOM). For more information, see Configuring Encoding Policy for a Service. |
Microsoft.ConnectedIndustry.ServiceModel.Application.EncodingExtensionElement |
ExtendedSecurityBindingElement |
Provides support for the DCS security and protection policies. This binding element enables a service to follow the WS-Trust specification for authenticating users and establishing a secure communications channel between a client application and a service. For more information, see Configuring Security Policy for a Service. |
Microsoft.ConnectedIndustry.ServiceModel.Application.SecurityExtensionElement |
BusinessLogBindingElement |
Provides support for the DCS Business Log policy. Business logging enables a service to record information about each request sent to a service in a SQL Server database. For more information, see Configuring Business Logging Policy for an Operation. |
Microsoft.ConnectedIndustry.ServiceModel.Application.BusinessLogging.BusinessLogExtensionElement |
CachingBindingElement |
Provides support for DCS response caching. A DCS service can configure caching policy for its operations, and the responses returned by these operations can be cached by a client application. For more information, see Configuring Caching Policy for an Operation. |
Microsoft.ConnectedIndustry.ServiceModel.Application.Caching.CachingExtensionElement |
ContextBindingElement |
Provides support for passing context information in the SOAP header of request and response messages. For more information, see Configuring Context Policy for an Operation. |
Microsoft.ConnectedIndustry.ServiceModel.Application.Context.ContextExtensionElement |
IdentityBindingElement |
Provides support for the Identity Policy in Service Pack 1. This policy enables a client application to provide a Service Principal Name (SPN) or User Principal Name (UPN) with a request message when the service uses Kerberos security. For more information, see Configuring Identity Policy for a Service. |
Microsoft.ConnectedIndustry.ServiceModel.ProtocolChannels.Identity.IdentityExtensionElement |
CorrelatorBindingElement |
Provides support for correlating request and response messages in duplex channels. In a duplex channel, this binding element creates a CorrelatorListenerFactory object to correlate messages. This element exposes the listenUri property that specifies the client callback address. |
Microsoft.ConnectedIndustry.ServiceModel.ProtocolChannels.Correlator.CorrelatorBindingElementExtensionElement |
The EncodingExtensionElement, SecurityExtensionElement, BusinessLogExtensionElement, CachingExtensionElement, and ContextExtensionElement classes are located in the Microsoft.ConnectedIndustry.ServiceModel.Application assembly. The IdentityExtensionElement and CorrelatorExtensionElement classes are in the Microsoft.ConnectedIndustry.ServiceModel assembly.
Notes on the DCS Binding Element Extension Classes
If the transactionFlow property in the binding configuration of the extendedHttpBinding binding is set to true, the TransactionFlowBindingElement element is also added to the stack (with transaction protocol as WSAtomicTransactionOctober2004). This binding element is added between extended encoding and security binding elements.
If the isComposite property in the binding configuration of the extendedHttpBinding binding is set to true, the CorrelatorBindingElement and OneWayBindingElement elements are also added to the stack. This binding element is added between identity and transport binding elements.
Configuring a Custom Binding with DCS Binding Elements
You can specify the extendedHttpBinding binding for a DCS service without performing any additional configuration. However, you can compose a custom binding for a DCS service that selects DCS binding elements and binding elements from other sources. For example, your service might require a custom binding that includes each of the DCS binding elements but that also provides support for reliable messaging or long-running transactions.
To configure a custom binding by using the DCS binding elements
Add the DCS binding element extension classes to the <extensions> section of the <system.ServiceModel> configuration. The following example adds the DCS caching, business log, context, encoding, security, and identity extension elements to the configuration.
-
<system.serviceModel> ... <extensions> <bindingExtensions> ... </bindingExtensions> <bindingElementExtensions> <add name="dcsCaching" type="Microsoft.ConnectedIndustry.ServiceModel.Application.Caching.CachingExtensionElement, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="dcsBusinessLog" type="Microsoft.ConnectedIndustry.ServiceModel.Application.BusinessLogging.BusinessLogExtensionElement, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="dcsContext" type="Microsoft.ConnectedIndustry.ServiceModel.Application.Context.ContextExtensionElement, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="dcsEncoding" type="Microsoft.ConnectedIndustry.ServiceModel.Application.EncodingExtensionElement, Microsoft.ConnectedIndustry.ServiceModel.Application,Version=1.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="dcsSecurity" type="Microsoft.ConnectedIndustry.ServiceModel.Application.SecurityExtensionElement, Microsoft.ConnectedIndustry.ServiceModel.Application,Version=1.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="dcsIdentity" type="Microsoft.ConnectedIndustry.ServiceModel.ProtocolChannels.Identity.IdentityExtensionElement, Microsoft.ConnectedIndustry.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </bindingElementExtensions> </extensions> </system.serviceModel>
Create a custom binding that composes the DCS binding elements and any other binding elements required. The following example constructs a custom binding that includes each of the DCS binding elements with the <httpTransport> element provided with WCF.
-
Note
You must provide a transport binding element appropriate to the URI of the endpoint that hosts the service. DCS does not provide a custom transport binding element but does support the WCF–provided transports such as HTTP and TCP.
Alternatively, you can use a custom endpoint selector that inserts an appropriate transport binding element based on the URI of the endpoint. For more information, see Building a Custom Endpoint Selector. -
<system.serviceModel> ... <bindings> <customBinding> <binding name="customDCSBinding"> <dcsCaching/> <dcsBusinessLog/> <dcsContext/> <dcsEncoding/> <dcsSecurity/> <dcsIdentity/> <httpTransport/> </binding> </customBinding> ... </bindings> ... </system.serviceModel>
-
Note
The ContextExtensionElement class that is used to instantiate the DCS context binding element exposes a Boolean property called enable. If you set the enable property to false (the default) then the presence or absence of the context policy for the service determines whether the service expects sends and receives context information in the headers of the request and response messages that it processes. If you set the enable property to true, then the service must implement the context policy.
Reference the custom binding in the <serviceFactory> configuration in the <cis.serviceModel> section of the configuration file. The following code fragment shows an example.
-
<cis.serviceModel> <serviceFactory> <httpBaseAddress dnsAlias="hostName"/> <defaultServiceConfiguration serviceBehavior="DCSBehavior"> <defaultEndpoint behaviorConfiguration="enableTracing"> <defaultSimplexBinding binding="customDCSBinding"/> <defaultDuplexBinding binding="extendedHttpBinding" bindingConfiguration="duplex"/> </defaultEndpoint> </defaultServiceConfiguration> </serviceFactory> ... </cis.serviceModel>
See Also
BindingElementExtensionElement Class
Configuring Encoding Policy for a Service
Configuring Security Policy for a Service
Configuring Business Logging Policy for an Operation
Configuring Caching Policy for an Operation
Configuring Context Policy for an Operation