Which line of code should you insert at line 04?

A Windows Communication Foundation (WCF) service is self-hosted in a console application.
The service implements the IDataAccess contract, which is defined in the MyApplication namespace.
The service is implemented in a class named DataAccessService which implements the IDataAccess
interface and also is defined in the MyApplication namespace. The hosting code is as follows.
(Line numbers are included for reference only.)

01 static void Main(string[] args)
02 {
03 ServiceHost host;
04 …
05 host.Open();
06 Console.ReadLine();
07 host.Close();
08 }

You need to create a ServiceHost instance and assign it to the host variable. You also need to instantiate the service host.
Which line of code should you insert at line 04?

A Windows Communication Foundation (WCF) service is self-hosted in a console application.
The service implements the IDataAccess contract, which is defined in the MyApplication namespace.
The service is implemented in a class named DataAccessService which implements the IDataAccess
interface and also is defined in the MyApplication namespace. The hosting code is as follows.
(Line numbers are included for reference only.)

01 static void Main(string[] args)
02 {
03 ServiceHost host;
04 …
05 host.Open();
06 Console.ReadLine();
07 host.Close();
08 }

You need to create a ServiceHost instance and assign it to the host variable. You also need to instantiate the service host.
Which line of code should you insert at line 04?

A.
host = new ServiceHost(“MyApplication.DataAccessService”);

B.
host = new ServiceHost(“MyApplication.DataAccess”);

C.
host = new ServiceHost(typeof(IDataAccess));

D.
host = new ServiceHost(typeof(DataAccessService));

Explanation:
Constructors

ServiceHost() Initializes a new instance of the ServiceHost class.
ServiceHost(Object, Uri[]) Initializes a new instance of the ServiceHost class with the instance of the service and its base addresses specified.
ServiceHost(Type, Uri[]) Initializes a new instance of the ServiceHost class with the type of service and its base addresses specified.

ServiceHost Class
(http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx)



Leave a Reply 1

Your email address will not be published. Required fields are marked *