PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing a Windows Communication Foundation (WCF) service that contains the following code segment.

[ServiceContract]
public interface ICustomerService
{

}
public class CustomerService : ICustomerService
{

}

The service is self-hosted in a console application. Older client applications access the service at http://contoso.com:8080/CustomerService/V1.
Newer client applications access the service at http://contoso.com:8080/CustomerService/V2.
You need to ensure that any client application can access the service at either address. Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Uri serviceAddress1 = new Uri(“http://contoso.com:8080/CustomerService/V1”);
Uri serviceAddress2 = new Uri(“http://contoso.com:8080/CustomerService/V2”);
ServiceHost host = new ServiceHost(typeof(ICustomerService), new Uri[]{ serviceAddress1, serviceAddress2 });

B.
Uri serviceAddress1 = new Uri(“http://contoso.com:8080/CustomerService/V1”);
Uri serviceAddress2 = new Uri(“http://contoso.com:8080/CustomerService/V2”);
ServiceHost host = new ServiceHost(typeof(CustomerService), new Uri[]{ serviceAddress1, serviceAddress2 });

C.
Uri serviceAddress = new Uri(“http://contoso.com:8080/”);
ServiceHost host = new ServiceHost(typeof(CustomerService), new Uri[]{ serviceAddress });
host.AddServiceEndpoint(typeof(ICustomerService), new BasicHttpBinding(), “CustomerService/V1”);
host.AddServiceEndpoint(typeof(ICustomerService), new BasicHttpBinding(), “CustomerService/V2”);

D.
Uri serviceAddress = new Uri(“http://contoso.com:8080/”);
ServiceHost host = new ServiceHost(typeof(ICustomerService), new Uri[] { serviceAddress });
host.AddServiceEndpoint(typeof(CustomerService), new BasicHttpBinding(), “CustomerService/V1”);
host.AddServiceEndpoint(typeof(CustomerService), new BasicHttpBinding(), “CustomerService/V2”);

Explanation:
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)

Data Contract Versioning
(http://msdn.microsoft.com/en-us/library/ms731138%28v=VS.100%29.aspx)

Best Practices: Data Contract Versioning
(http://msdn.microsoft.com/en-us/library/ms733832.aspx)

ServiceHost.AddServiceEndpoint (String, Binding, String) Adds a service endpoint to the hosted service with a specified contract, binding, and endpoint address.
ServiceHost.AddServiceEndpoint (String, Binding, Uri) Adds a service endpoint to the hosted service with a specified contract, binding, and a URI that contains the endpoint address.
ServiceHost.AddServiceEndpoint (Type, Binding, String) Adds a service endpoint to the hosted service with a specified contract, binding, and endpoint address.
ServiceHost.AddServiceEndpoint (Type, Binding, Uri) Adds a service endpoint to the hosted service with a specified contract, binding, and URI that contains the endpoint address.
ServiceHost.AddServiceEndpoint (String, Binding, String, Uri) Adds a service endpoint to the hosted service with a specified contract, binding, endpoint address and URI that contains address at which it listens.
ServiceHost.AddServiceEndpoint (String, Binding, Uri, Uri) Adds a service endpoint to the hosted service with a specified contract, binding, and URIs that contain the endpoint and listening addresses.
ServiceHost.AddServiceEndpoint (Type, Binding, String, Uri) Adds a service endpoint to the hosted service with a specified contract, binding, an endpoint address, and a URI on which the service listens.
ServiceHost.AddServiceEndpoint (Type, Binding, Uri, Uri) Adds a service endpoint to the hosted service with a specified contract, binding, a URI that contains the endpoint address, and a URI on which the service listens

One Comment on “Which code segment should you use?


Leave a Reply