A Windows Communication Foundation (WCF) solution provides a session-based counter.
The service is self-hosted. The hosting code is as follows:
ServiceHost host = new ServiceHost(typeof(CounterService));
NetTcpBinding binding1 = new NetTcpBinding(SecurityMode.None);
host.AddServiceEndpoint(“MyApplication.ICounterService”, binding1, “net.tcp://localhost:23456”);
host.Open();
This service is currently exposed over TCP, but needs to be exposed to external clients over HTTP.
Therefore, a new service endpoint is created with the following code:
host.AddServiceEndpoint(“MyApplication.ICounterService”, binding2, “http://localhost:12345”);
You need to complete the implementation and ensure that the session-based counter will perform over HTTP as it does over TCP.
What should you do?
A.
Define binding2 as follows:
WS2007HttpBinding binding2 = new WS2007HttpBinding(SecurityMode.None);
Configure binding2 as follows:
binding2.ReliableSession.Enabled = true;
B.
Define binding2 as follows:
WSHttpBinding binding2 = new WSHttpBinding(SecurityMode.None);
Add the following behavior to the service implementation:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
C.
Define binding2 as follows:
BasicHttpBinding binding2 = new BasicHttpBinding(BasicHttpSecurityMode.None);
Enable cookies for binding2.
binding2.AllowCookies = true:
D.
Define binding2 as follows:
BasicHttpBinding binding2 = new BasicHttpBinding(BasicHttpSecurityMode.None);
Add the following behavior to the service implementation:
[ServiceBehavior(InstanceContexMode = InstanceContextMode.Single)]
Explanation:
WS2007HttpBinding Class
(http://msdn.microsoft.com/en-us/library/system.servicemodel.ws2007httpbinding.aspx)WS2007HttpBinding Class
Represents an interoperable binding that derives from WSHttpBinding and provides support for
the updated versions of the Security, ReliableSession, and TransactionFlow binding elements.The WS2007HttpBinding class adds a system-provided binding similar to WSHttpBinding but uses
the Organization for the Advancement of Structured Information Standards (OASIS) standard versions of the ReliableSession,
Security, and TransactionFlow protocols. No changes to the object model or default settings are required when using this binding.
A