Professional Documents
Culture Documents
Windows®
Communication
Foundation
Module 3: Endpoints and Behaviors
• Exposing WCF Services over Different Endpoints
• HTTP-Based Bindings
• Connection-Oriented Bindings
• Queue-Based Bindings
• Configuring Bindings
Contract B Contract A
Encoding
Client Transport
Channel
• BasicHttpBinding
• WsHttpBinding
• WsDualHttpBinding
• WsFederationHttpBinding
Connection-Oriented Bindings
• NetTcpBinding
• NetNamedPipeBinding
Queue-Based Bindings
• NetMsmqBinding
• MsmqIntegrationBinding
Changing an Endpoint to Use a Different Binding
<service name="ConnectedWCF.BankService">
<endpoint address="BankService"
binding="basicHttpBinding"
contract="ConnectedWCF.IBank"/>
<host>
<baseAddresses>
<baseAddress baseAddress="http://localhost:8080/Simple"/>
</baseAddresses>
</host>
</service>
<service name="ConnectedWCF.BankService">
<endpoint address="BankService"
binding="netTcpBinding"
contract="ConnectedWCF.IBank" /> Change binding
<host> attribute and address
<baseAddresses>
<baseAddress baseAddress="net.tcp://localhost:9001/Simple"/>
</baseAddresses>
</host>
</service>
Using Both Bindings
<service name="ConnectedWCF.BankService">
<endpoint address="BankService"
binding="basicHttpBinding"
contract="ConnectedWCF.IBank"/>
<endpoint address="BankService"
binding="netTcpBinding"
contract="ConnectedWCF.IBank"/>
<host>
<baseAddresses>
<baseAddress
baseAddress="http://localhost:8080/Simple"/>
<baseAddress
baseAddress="net.tcp://localhost:9001/Simple"/>
</baseAddresses>
</host>
</service>
Exposing Multiple Contracts
<services>
<service name="ConnectedWCF.BankService">
<endpoint address="BankService"
binding="basicHttpBinding"
contract="ConnectedWCF.IBank"/>
<host>
<baseAddresses>
<baseAddress
baseAddress="http://localhost:8080/Simple"/>
</baseAddresses>
</host>
</service>
<service name="ConnectedWCF.OrderingService">
<endpoint address="OrderingService"
binding="basicHttpBinding"
contract="ConnectedWCF.IOrdering"/>
<host>
<baseAddresses>
<baseAddress
baseAddress="http://localhost:8080/Simple"/>
</baseAddresses>
</host>
</service>
</services>
Configuring Bindings
<system.serviceModel>
<services>
<service name="BankService" >
<endpoint address="http://localhost:8080/BankService"
contract="IBankService"
binding="basicHttpBinding"
bindingConfiguration="myBasicHttpBindingConfig"/>
</service>
</services>
</system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="myBasicHttpBindingConfig">
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
Demonstration: Using a Different Binding
In this demonstration, you will see how to change the
binding used by a WCF client and service
Lesson: Adding Behaviors to Services and Endpoints
• WCF Behaviors
• Service Behaviors
• Operation Behaviors
• Endpoint Behaviors
WCF Configuration
WCF Runtime
Behavior
Configuration
Service Behaviors
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class BankService : IBank
{
...
}
<services>
<service name="ConnectedWCF.BankService"
behaviorConfiguration="metadataAndDebugEnabled">
...
</service>
</services>
<behaviors>
<serviceBehaviors
<behavior name="metadataAndDebugEnabled">
<serviceDebug includeExceptionDetailInFaults="true" /
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
</behavior>
</serviceBehaviors>
</behaviors>
Operation Behaviors
[OperationBehavior(TransactionAutoComplete = true,
TransactionScopeRequired = true)]
[TransactionFlow(TransactionFlowOption.Mandatory)]
public string Transfer(string sourceAccount, decimal amount)
{
...
}
Endpoint Behaviors
<system.serviceModel>
<services>
<service name="BankService" >
<endpoint address="http://localhost:8080/BankService"
contract="IBankService"
binding="basicHttpBinding"
bindingConfiguration="myBasicHttpBindingConfig"
behaviorConfiguration="bankServiceCredentialBehavior"/>
</service>
</services>
</system.serviceModel>
<endpointBehaviors>
<behavior
name="bankServiceCredentialBehavior">
<!– Configuration elements go here. -->
</behavior>
</endpointBehaviors>
Demonstration: Adding Metadata Exchange to a
WCF Service by Using a Behavior
In this demonstration, you will see how to use a service
behavior to add metadata exchange capability to a WCF
service
Notes Page Over-flow Slide. Do Not Print Slide.
See Notes pane.
Lesson: Interoperating with Non-WCF Web Services
• Overview of WCF Web Service Interoperability
ReliableSessionBindingElement rel =
new ReliableSessionBindingElement();
HttpTransportBindingElement trans =
new HttpTransportBindingElement();
trans.AuthenticationScheme = AuthenticationSchemes.Anonymous;
trans.HostNameComparisonMode =
HostNameComparisonMode.StrongWildcard;
Logon information
Password Pa$$w0rd
• Best Practices