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 name | Description | Type |
---|---|---|
BasicHttpBindingSurrogate | Specifies 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 |
WSHttpBindingSurrogate | Specifies an interoperable binding that supports distributed transactions and secure, reliable sessions. | Class |
CustomBindingSurrogate | Specifies 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 |
BasicHttpSecuritySurrogate | Specifies the security settings of a basicHttpBinding binding. | Class |
HttpTransportSecuritySurrogate | Specifies the transport-level security settings for the WSHttpBinding. | Class |
OptionalReliableSessionSurrogate | Specifies convenient access to the properties of a reliable session. | Class |
ReaderQuotasSurrogate | Represents constraints on the complexity of SOAP messages that can be processed by endpoints configured with this binding. | Class |
SecurityAlgorithmSuiteValue | Specifies 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 |
TransferMode | Specifies whether a channel uses streamed or buffered modes for the transfer of request and response messages. | Enum |
SecurityMode | Specifies the security settings for a binding. | Enum |
WSMessageEncoding | Specifies whether Message Transmission Optimization Mechanism (MTOM) or text is used to encode SOAP messages. | Enum |
HostNameComparisonMode | Specifies how the host name is to be used in URI comparisons when dispatching an incoming message to a service endpoint. | Enum |
MessageCredentialType | Specifies valid message credential type. | Enum |
HttpClientCredentialType | Specifies valid credential for HTTP clients. | Enum |
HttpProxyCredentialType | Specifies 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.