Skip to main content
Version: 4.2.5

Binding using code expressions

The binding used by the consumer activity can be defined with code expressions.

When defining a binding using code expressions, the following types are of interest:

Type nameDescriptionType
BasicHttpBindingSurrogateSpecifies a binding that a Windows Communication Foundation (WCF) service can use to configure and expose endpoints that are able to communicate with ASMX-based Web services and clients and other services that conform to the WS-I Basic Profile 1.1.Class
WSHttpBindingSurrogateSpecifies an interoperable binding that supports distributed transactions and secure, reliable sessions.Class
CustomBindingSurrogateSpecifies a CustomBinding that is defined by a list of binding elements. Use this binding type when none of the other bindings meet the requirements of the web service.Class
BasicHttpSecuritySurrogateSpecifies the security settings of a basicHttpBinding binding.Class
HttpTransportSecuritySurrogateSpecifies the transport-level security settings for the WSHttpBinding.Class
OptionalReliableSessionSurrogateSpecifies convenient access to the properties of a reliable session.Class
ReaderQuotasSurrogateRepresents constraints on the complexity of SOAP messages that can be processed by endpoints configured with this binding.Class
SecurityAlgorithmSuiteValueSpecifies the key for the token requirement property, which has a value that is the algorithm suite that the channel uses to perform message security.Enum
TransferModeSpecifies whether a channel uses streamed or buffered modes for the transfer of request and response messages.Enum
SecurityModeSpecifies the security settings for a binding.Enum
WSMessageEncodingSpecifies whether Message Transmission Optimization Mechanism (MTOM) or text is used to encode SOAP messages.Enum
HostNameComparisonModeSpecifies how the host name is to be used in URI comparisons when dispatching an incoming message to a service endpoint.Enum
MessageCredentialTypeSpecifies valid message credential type.Enum
HttpClientCredentialTypeSpecifies valid credential for HTTP clients.Enum
HttpProxyCredentialTypeSpecifies valid credential types for HTTP proxy authentication.Enum

Basic Http binding using code expression

To define a basic http binding using code expression, an instance of BasicHttpBindingSurrogate must be returned by the code expression.

WS-Http binding using code expression

To define a WS-http binding using code expression, an instance of WSHttpBindingSurrogate must be returned by the code expression.

In the following example an instance of WSHttpBindingSurrogate is created by the code expression. The security mode of the binding is set to message security and the windows credential is used for authentication.

Creating a new WSHttpBindingSurrogate

new WSHttpBindingSurrogate() 
{
Security = new HttpTransportSecuritySurrogate()
{
Mode = SecurityMode.Message,
MessageClientCredentialType = MessageCredentialType.Windows
}
}

CustomBinding using code expression

To define a CustomBinding using code expression, an instance of CustomBindingSurrogate must be returned by the code expression.

In the following example, an instance of CustomBindingSurrogate is created by the code expression. The constructor takes a CustomBinding which is configured with two binding elements (a TextMessageEncodingBindingElement and a HttpTransportBindingElement) as parameter. Each binding element is configured with the desired parameters during initiation.

Creating a new CustomBindingSurrogate

        
new CustomBindingSurrogate(
new System.ServiceModel.Channels.CustomBinding(
new System.ServiceModel.Channels.TextMessageEncodingBindingElement()
{
MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap11,
WriteEncoding = Encoding.Unicode
},
new System.ServiceModel.Channels.HttpTransportBindingElement()
{
TransferMode = System.ServiceModel.TransferMode.Buffered,
ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Basic
}
)
)

For more information on when and how a CustomBinding can be used, see https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.channels.custombinding?view=netframework-4.8.