15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Binding ❘ 1301<br />

sT<strong>and</strong>ard binding<br />

NetNamedPipeBinding<br />

NetMsmqBinding<br />

MsmqIntegrationBinding<br />

CustomBinding<br />

desCriPTion<br />

NetNamedPipeBinding is optimized for communication between different<br />

processes on the same system.<br />

The binding NetMsmqBinding brings queued communication to WCF.<br />

Here, the messages are sent to the message queue.<br />

MsmqIntegrationBinding is the binding for existing applications that uses<br />

message queuing. In contrast, the binding NetMsmqBinding requires WCF<br />

applications both on the client <strong>and</strong> server.<br />

With a CustomBinding the transport protocol <strong>and</strong> security requirements can<br />

be completely customized.<br />

Depending on the binding, different features are supported. The bindings starting with WS are platformindependent,<br />

supporting Web services specifications. Bindings that start with the name Net use binary<br />

formatting for high-performance communication between .<strong>NET</strong> applications. Other features are support<br />

of sessions, reliable sessions, transactions, <strong>and</strong> duplex communication; the following table lists the bindings<br />

supporting these features.<br />

feaTure<br />

Sessions<br />

Reliable Sessions<br />

Transactions<br />

Duplex Communication<br />

binding<br />

WSHttpBinding, WSDualHttpBinding, WsFederationHttpBinding,<br />

NetTcpBinding, NetNamedPipeBinding<br />

WSHttpBinding, WSDualHttpBinding, WsFederationHttpBinding,<br />

NetTcpBinding<br />

WSHttpBinding, WSDualHttpBinding, WSFederationHttpBinding,<br />

NetTcpBinding, NetNamedPipeBinding, NetMsmqBinding,<br />

MsmqIntegrationBinding<br />

WsDualHttpBinding, NetTcpBinding, NetNamedPipeBinding,<br />

NetPeerTcpBinding<br />

Along with defining the binding, the service must define an endpoint. The endpoint is dependent on the<br />

contract, the address of the service, <strong>and</strong> the binding. In the following code sample, a ServiceHost object<br />

is instantiated, <strong>and</strong> the address http://localhost:8080/RoomReservation, a WsHttpBinding instance,<br />

<strong>and</strong> the contract are added to an endpoint of the service:<br />

static ServiceHost host;<br />

static void StartService()<br />

{<br />

var baseAddress = new Uri("http://localhost:8080/RoomReservation");<br />

host = new ServiceHost(<br />

typeof(RoomReservationService));<br />

}<br />

var binding1 = new WSHttpBinding();<br />

host.AddServiceEndpoint(typeof(IRoomService), binding1, baseAddress);<br />

host.Open();<br />

In addition to defining the binding programmatically, you can define it with the application configuration<br />

file. The configuration for WCF is placed inside the element . The <br />

element defines the services offered. Similarly, as you’ve seen in the code, the service needs an endpoint,<br />

<strong>and</strong> the endpoint contains address, binding, <strong>and</strong> contract information. The default binding configuration of<br />

wsHttpBinding is modified with the bindingConfiguration XML attribute that references the binding<br />

configuration wsHttpConfig1. This is the binding configuration you can find inside the <br />

section, which is used to change the wsHttpBinding configuration to enable reliableSession.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!