MS .Net Framework 70-513

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Akshansh
A
Akshansh
Community Contributor
Quizzes Created: 1 | Total Attempts: 155
Questions: 70 | Attempts: 155

SettingsSettingsSettings
DotNET Quizzes & Trivia

 70-513 - TS: Windows Communication Foundation Development via MS. NET Framework 4
Number of Questions Included: 145
Updated: 2012-05-28
This dump is the collection composed by Lyudmyla of all unique questions from dumps of BOB, FSAN and WASP, with Darths corrections.


Questions and Answers
  • 1. 

    You are creating a Windows Communication Foundation (WCF) service that is implemented as follows. (Line numbers are included for reference only.) 01 [ServiceContract] 02 [ServiceBehavior(IncludeExceptionDetailsInFaults = true)] 03 public class OrderService 04 { 05     [OperationContract] 06     public void SubmitOrder(Order anOrder) 07     { 08         try 09         { 10             ... 11         } 12         catch(DivideByZeroException ex) 13         { 14             ... 15         } 16     } 17 } You need to ensure that the stack trace details of the exception are not included in the error information sent to the client. What should you do?

    • A.

      Replace line 14 with the following line: throw;

    • B.

      Replace line 14 with the following line: throw new FaultException(anOrder, ex.ToString());

    • C.

      After line 05, add the following line: [FaultContract(typeof(FaultException))] Replace line 14 with the following line: throw ex;

    • D.

      Alter line 05, add the following line: [FaultContract(typeof(FaultException))] Replace line 14 with the following line: throw new FaultException(anOrder, "Divide by zero exception");

    Correct Answer
    D. Alter line 05, add the following line: [FaultContract(typeof(FaultException))] Replace line 14 with the following line: throw new FaultException(anOrder, "Divide by zero exception");
    Explanation
    To ensure that the stack trace details of the exception are not included in the error information sent to the client, you need to add the [FaultContract(typeof(FaultException))] attribute to the service contract at line 05. This attribute specifies that the service can throw a FaultException, which is a fault message that can be sent to the client. Additionally, you should replace line 14 with the following line: throw new FaultException(anOrder, "Divide by zero exception");. This will throw a FaultException with a custom error message instead of the original exception, preventing the stack trace details from being exposed to the client.

    Rate this question:

  • 2. 

    You are creating a Windows Communication Foundation (WCF) service. You do not want to expose the internal implementation at the service layer. You need to expose the following class as a service named Arithmetic with an operation named Sum: public class Calculator {     public int Add(int x, int y)     {     } } Which code segment should you use?

    • A.

      [ServiceContract(Namespace="Arithmetic")] public class Calculator { [Operation Contract(Action="Sum")] public int Add(int x, int y) {} }

    • B.

      [ServiceContract(ConfigurationName="Arithmetic")] public class Calculator { [Operation Contract(Action="Sum")] public int Add(int x, int y) {} }

    • C.

      [ServiceContract(Name="Arithmetic")] public class Calculator { [OperationContract(Name="Sum")] public int Add(int x, int y) {} }

    • D.

      [ServiceContract(Name="Arithmetic")] public class Calculator { [OperationContract(ReplyAction="Sum")] public int Add(int x, int y) {} }

    Correct Answer
    C. [ServiceContract(Name="Arithmetic")] public class Calculator { [OperationContract(Name="Sum")] public int Add(int x, int y) {} }
    Explanation
    The correct answer is [ServiceContract(Name="Arithmetic")]
    public class Calculator
    {
    [OperationContract(Name="Sum")]
    public int Add(int x, int y)
    {}
    }

    This is the correct code segment because it uses the ServiceContract attribute with the Name property set to "Arithmetic" to specify the name of the service. It also uses the OperationContract attribute with the Name property set to "Sum" to specify the name of the operation. This allows the class and method to be exposed as a service named "Arithmetic" with an operation named "Sum".

    Rate this question:

  • 3. 

    You are developing a data contract for a Windows Communication Foundation (WCF) service. The data in the data contract must participate in round trips. Strict schema validity is not required. You need to ensure that the contract is forward-compatible and allows new data members to be added to it. Which interface should you implement in the data contract class?

    • A.

      ICommunicationObject

    • B.

      IExtension

    • C.

      IExtensibleObject

    • D.

      IExtensibleDataObject

    Correct Answer
    D. IExtensibleDataObject
    Explanation
    The correct answer is IExtensibleDataObject. By implementing the IExtensibleDataObject interface, the data contract class allows new data members to be added without breaking existing functionality. This interface provides a mechanism for adding extra data to the serialized message without requiring a strict schema validation. It ensures forward compatibility by allowing the addition of new data members without affecting existing contracts.

    Rate this question:

  • 4. 

    A Windows Communication Foundation (WCF) application uses a data contract that has several data members. You need the application to throw a SerializationException if any of the data members are not present when a serialized instance of the data contract is deserialized. What should you do?

    • A.

      Add the KnownType attribute to the data contract. Set a default value in each of the data member declarations.

    • B.

      Add the KnownType attribute to the data contract. Set the Order property of each data member to unique integer value.

    • C.

      Set the EmitDefaultValue property of each data member to false.

    • D.

      Set the lsRequired property of each data member to true.

    Correct Answer
    D. Set the lsRequired property of each data member to true.
    Explanation
    Setting the lsRequired property of each data member to true ensures that the data contract requires all data members to be present when a serialized instance is deserialized. If any data member is missing, a SerializationException will be thrown. This is the correct approach to achieve the desired behavior.

    Rate this question:

  • 5. 

    A Windows Communication Foundation (WCF) application uses the following data contract [DataContract] public class Person {     [DataMember]     public string firstName;     [DataMember]     public string lastName;     [DataMember]     public int age;     [DataMember]     public int ID;     } You need to ensure that the following XML segment is generated when the data contract is serialized. <Person>     <firstName xsi:nil="true"/>     <lastName xsi:nil="true"/>     <ID>999999999<ID> </Person> Which code segment should you use?

    • A.

      [DataMember] public string firstName; [DataMember] public string lastName; [DataMember(EmitDefaultValue = true)] public int age = 0; [DataMember(EmitDefaultvValue = true)] public int ID = 999999999;

    • B.

      [DataMember(EmitDefaultValue = false)] public string firstName = null; [DataMember(EmitDefaultValue = false)] public string lastName = null; [DataMember(EmitDefaultValue = true)] public int age = -1; [DataMember(EmitDefaultValue = false)] public int ID = 999999999;

    • C.

      [DataMember(EmitDefaultValue = true)] public string firstName; [DataMember(EmitDefaultValue = true)] public string lastName; [DataMember(EmitDefaultValue = false)] public int age = -1; [DataMember(EmitDefaultValue = false)] public int ID = 999999999;

    • D.

      [DataMember] public string firstName = null; [DataMember] public string lastName = null; [DataMember(EmitDefaultValue = false)] public int age = 0; [DataMember(EmitDefaultValue = false)] public int ID = 999999999;

    Correct Answer
    D. [DataMember] public string firstName = null; [DataMember] public string lastName = null; [DataMember(EmitDefaultValue = false)] public int age = 0; [DataMember(EmitDefaultValue = false)] public int ID = 999999999;
    Explanation
    The correct answer is to use the code segment:
    [DataMember]
    public string firstName = null;
    [DataMember]
    public string lastName = null;
    [DataMember(EmitDefaultValue = false)]
    public int age = 0;
    [DataMember(EmitDefaultValue = false)]
    public int ID = 999999999;

    This code segment ensures that the firstName and lastName properties are serialized as empty elements by setting them to null. The age property is set to 0 and the ID property is set to 999999999, which are the desired values for serialization. The EmitDefaultValue property is set to false for all properties to prevent the default values from being serialized.

    Rate this question:

  • 6. 

    The following is an example of a SOAP envelope.      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope">     <s:Header>         <h:StoreId xmlns:h="http://www.contoso.com">6495</h:StoreId>     </s:Header>     <s:Body>         <CheckStockRequest xmlns="http://www.contoso.com">             <ItemId>2469<ItemId>         </CheckStockRequest>     </s: Body> </s:Envelope> You need to create a message contract that generates the SOAP envelope. Which code segment should you use?

    • A.

      [MessageContract(WrapperName="http://www.contoso.com")] public class CheckStockRequest { [MessageHeader(Namespace="http://www.contoso.com")] public int StoreId { get; set; } [MessageBodyMember(Namespace="http://www.contoso.com")] public int ItemId { get; set; } }

    • B.

      [MessageContract(WrapperNamespace="http://www.contoso.com")] public class CheckStockRequest { [MessageHeader(Namespace="http://www.contoso.com")] public int StoreId { get; set; } [MessageBodyMember(Namespace="http://www contoso.com")] public int ItemId { get; set; } }

    • C.

      [MessageContract(WrapperNamespace="http://www.contoso.com")] public class CheckStockRequest { [MessageHeader(Namespace="http://www.contoso.com")] public int StoreId { get; set; } public int ItemId { get; set; } }

    • D.

      [MessageContract(WrapperNamespace="http://www.contoso.com")] public class CheckStockRequest { [MessageHeader(Namespace="http://www.contoso.com")] public int StoreId { get; set; } [MessageBodyMember] public int ItemId { get; set; } }

    Correct Answer
    D. [MessageContract(WrapperNamespace="http://www.contoso.com")] public class CheckStockRequest { [MessageHeader(Namespace="http://www.contoso.com")] public int StoreId { get; set; } [MessageBodyMember] public int ItemId { get; set; } }
    Explanation
    The correct answer is [MessageContract(WrapperNamespace="http://www.contoso.com")]. This is because the given SOAP envelope has a namespace of "http://www.contoso.com" defined in the Envelope element. To generate a SOAP envelope that matches this structure, the MessageContract attribute should specify the same namespace using the WrapperNamespace property. Additionally, the StoreId property should have the MessageHeader attribute with the same namespace specified, and the ItemId property should have the MessageBodyMember attribute.

    Rate this question:

  • 7. 

    You are developing a client that sends several types of SOAP messages to a Windows Communication Foundation (WCF) service method named PostData. PostData is currently defined as follows: [OperationContract] void PostData(Order data); You need to modify PostData so that it can receive any SOAP message.  Which code segment should you use?

    • A.

      [OperationContract(IsOneWay=true, Action="*", ReplyAction="*")] void PostData(Order data);

    • B.

      [OperationContract(IsOneWay=true, Action="*", ReplyAction = "*")] void PostData(BodyWriter data);

    • C.

      [OperationContract] void PostData(BodyWriter data);

    • D.

      [OperationContract] void PostData(Message data);

    Correct Answer
    D. [OperationContract] void PostData(Message data);
    Explanation
    The correct answer is [OperationContract] void PostData(Message data) because the Message class in WCF represents the entire SOAP message, including the headers and body. By using this code segment, the PostData method can receive any SOAP message, regardless of its content or structure.

    Rate this question:

  • 8. 

    A class named TestService implements the following interface:      [ServiceContract] public interface ITestService {     [OperationContract]     DateTime GetServiceTime(); } TestService is hosted in an ASP.NET application. You need to modify the application to allow the GetServiceTime method to return the data formatted as JSON. It must do this only when the request URL ends in /ServiceTime. What should you do?

    • A.

      Add this attribute to the GetServiceTime method. [WebInvoke(Method="POST")] In the web.config file, add this element to system.serviceModel/behaviors/endpointBehaviors. In the web.config file, configure TestService in the system.serviceModel/services collection as follows:

    • B.

      Add this attribute to the GetServiceTime method. [WebInvoke(Method="GET", UriTemplate="/ServiceTime", ResponseFormat=WebMessageFormat.Json)] In the web.config file, configure TestService in the system.serviceModel/services collection as follows:

    • C.

      Add this attribute to the GetServiceTime method [WebGet(ResponseFormat=WebMessageFormat.Json, UriTemplate="/ServiceTime")] Create a new svc file named Jsonversion.svc with the following content.

    • D.

      Add this attribute to the GetServiceTime method. [WebGet(UriTemplate="Json)/ServiceTime")] Create a new .svc file named Jsonversion.svc with the following content

    Correct Answer
    C. Add this attribute to the GetServiceTime method [WebGet(ResponseFormat=WebMessageFormat.Json, UriTemplate="/ServiceTime")] Create a new svc file named Jsonversion.svc with the following content.
    Explanation
    The correct answer is to add the attribute [WebGet(ResponseFormat=WebMessageFormat.Json, UriTemplate="/ServiceTime")] to the GetServiceTime method. This attribute specifies that the method should be invoked using the HTTP GET method, and the response should be formatted as JSON. The UriTemplate="/ServiceTime" ensures that this behavior is applied only when the request URL ends in /ServiceTime.

    Rate this question:

  • 9. 

    You are creating a Windows Communication Foundation (WCF) service that implements operations in a RESTful manner.   You need to add a delete operation. You implement the delete method as follows: void DeleteItems(string id); You need to configure WCF to call this method when the client calls the service with the HTTP DELETE operation.  What should you do?

    • A.

      Add the WebInvoke(UriTemplate="/Items/{id}", Method="DELETE") attribute to the operation

    • B.

      Add the HttpDelete atribute to the operation

    • C.

      Replace the string parameter with a RemovedActivityAction parameter

    • D.

      Replace the return type with RemovedActivityAction.

    Correct Answer
    A. Add the WebInvoke(UriTemplate="/Items/{id}", Method="DELETE") attribute to the operation
    Explanation
    The correct answer is to add the WebInvoke(UriTemplate="/Items/{id}", Method="DELETE") attribute to the operation. This is because the WebInvoke attribute is used to specify the HTTP verb and URI template for a RESTful operation in WCF. In this case, the attribute is set to Method="DELETE" to indicate that the operation should be called when the client uses the HTTP DELETE method. The UriTemplate="/Items/{id}" specifies the URI template for the operation, where {id} is a placeholder for the ID parameter that will be passed in the URL.

    Rate this question:

  • 10. 

    A Windows Communication Foundation (WCF) service uses the following service contract. [ServiceContract] public interface IService {     [OperationContract]     string Operation1(string s); } You need to ensure that the operation contract Operation1 responds to HTTP POST requests. Which code segment should you use?

    • A.

      [OperationContract] [WebInvoke(Method="POST")] string Operation1(string s);

    • B.

      [OperationContract] [WebGet(UriTemplate="POST")] string Operation1(string s);

    • C.

      [OperationContract(ReplyAction="POST")] string Operation1(string s);

    • D.

      [OperationContract(Action="POST")] string Operation1(string s);

    Correct Answer
    A. [OperationContract] [WebInvoke(Method="POST")] string Operation1(string s);
    Explanation
    The correct answer is [OperationContract]
    [WebInvoke(Method="POST")]
    string Operation1(string s).

    This code segment uses the [WebInvoke] attribute with the Method property set to "POST", which ensures that the Operation1 method responds to HTTP POST requests.

    Rate this question:

  • 11. 

    A Windows Communication Foundation (WCF) service implements a contract with one-way and request-reply operations. The service is exposed over a TCP transport. Clients use a router to communicate with the service. The router is implemented as follows.  (Line numbers are included for reference only.) 01 ServiceHost host = new ServiceHost(typeof(RoutingService)); 02 host.AddServiceEndpoint( 03     typeof(ISimplexDatagramRouter), 04     new NetTcpBinding(), "net.tcp://localhost/Router" 05    ); 06 List<ServiceEndpoint> lep = new List<ServiceEndpoint>(); 07 lep.Add( 08     new ServiceEndpoint( 09        ContractDescription.GetContract( 10           typeof(ISimplexDatagramRouter) 11    ), 12     new NetTcpBinding(), 13     new EndpointAddress("net.tcp://localhost:8080/Logger") 14    ) 15 ); 16 RoutingConfiguration rc = new RoutingConfiguration(); 17 rc.FilterTable.Add(new MatchAllMessageFilter(), lep); 18 host.Description.Behaviors.Add(new RoutingBehavior(rc)); Request-reply operations are failing. You need to ensure that the router can handle one-way and request-reply operations. What should you do?

    • A.

      Change line 03 as follows: typeof(IRequestReplyRouter),

    • B.

      Change line 03 as follows: typeof(IDuplexSessionRouter),

    • C.

      Change line 10 as follows: typeof(IRequestReplyRouter)

    • D.

      Change line 10 as follows: typeof(IDuplexSessionRouter)

    Correct Answer
    B. Change line 03 as follows: typeof(IDuplexSessionRouter),
    Explanation
    The correct answer is to change line 03 to typeof(IDuplexSessionRouter). This is because the router needs to handle both one-way and request-reply operations, and the IDuplexSessionRouter interface supports both types of operations. By changing the line to typeof(IDuplexSessionRouter), the router will be able to handle both types of operations successfully.

    Rate this question:

  • 12. 

    You are modifying an existing Windows Communication Foundation (WCF) service that is defined as follows: [ServiceContract] public interface IMessageProcessor {     [OperationContract]     void ProcessMessages(); } public class MessageProcessor: IMessageProcessor     {      public void ProcessMessage();      SubmitOrder(); } SubmitOrder makes a call to another service. The ProcessMessage method does not perform as expected under a heavy load. You need to enable processing of multiple messages. New messages must only be processed when the ProcessMessage method is not processing requests, or when it is waiting for calls to SubmitOrder to return. Which attribute should you apply to the MessageProcessor class?

    • A.

      CallbackBehavior(ConcurrencyMode=ConcurencyMode.Reentrant)

    • B.

      CallbackBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)

    • C.

      ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)

    • D.

      ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)

    Correct Answer
    C. ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)
    Explanation
    The correct answer is ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant). This attribute should be applied to the MessageProcessor class in order to enable processing of multiple messages. The ConcurrencyMode.Reentrant setting allows the ProcessMessage method to handle multiple requests simultaneously, while also allowing it to wait for calls to SubmitOrder to return. This ensures that new messages are only processed when the ProcessMessage method is not already processing requests.

    Rate this question:

  • 13. 

    A Windows Communication Foundation (WCF) service listens for messages at net.tcp://www.contoso.com/MyService. It has a logical address at http://www.contoso.com/MyService. The configuration for the WCF client is as follows: <endpoint address="http://www.contoso.com/MyService"     binding="netTcpBinding"     bindingConfiguraton="NetTcpBinding_IMyService"     contract="ServiceReference1.IMyService"     name="NetTcpBinding_IMyService"/> The generated configuration does not provide enough information for the client to communicate with the server. You need to update the client so that it can communicate with the server. What should you do?

    • A.

      In the client configuration, change the value of the address attribute to net.tcp://www.contoso.com/MyService

    • B.

      In the client configuration, change the value of the address attribute to net.tcp://www.contoso.com/MyService listen=http://www.contoso.com/MyService.

    • C.

      After instantiating the client and before invoking any service operation, add this line of code. EndpointBehaviors.Add(new EndpointDiscoveryBehavior(){ Enabled = true });

    • D.

      After instantiating the client and before invoking any service operation, add this line of code. client.Endpoint.Behaviors.Add(new ClientViaBehavior(new Uri("net.tcp://www.contoso.com/IMyService")));

    Correct Answer
    D. After instantiating the client and before invoking any service operation, add this line of code. client.Endpoint.Behaviors.Add(new ClientViaBehavior(new Uri("net.tcp://www.contoso.com/IMyService")));
    Explanation
    The correct answer is to add the line of code "client.Endpoint.Behaviors.Add(new ClientViaBehavior(new Uri("net.tcp://www.contoso.com/IMyService")));". This code adds a behavior to the client's endpoint, specifically the ClientViaBehavior, which allows the client to specify a different URI for sending messages. In this case, it sets the URI to "net.tcp://www.contoso.com/IMyService", which matches the URI of the server's net.tcp endpoint. This ensures that the client can communicate with the server using the correct URI.

    Rate this question:

  • 14. 

    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));

    Correct Answer
    D. Host = new ServiceHost(typeof(DataAccessService));
    Explanation
    The correct line of code to insert at line 04 is "host = new ServiceHost(typeof(DataAccessService));". This is because the ServiceHost constructor requires the type of the service to be hosted, which in this case is DataAccessService.

    Rate this question:

  • 15. 

    A Windows Communication Foundation (WCF) service implements the following contract. [ServiceContract] public interface IHelloService {     [OperationContract(WebGet(UriTemplate="hello?name={name}"))]     string SayHello(string name); } The implementation is as follows: public class HelloService: IHelloService {      public string SayHello(string name)      {         return "Hello " + name;      } } The service is self-hosted, and the hosting code is as follows: WebServiceHost svcHost = CreateHost(); svcHost.Open(); Console.ReadLine(); svcHost.Close(); You need to implement CreateHost so that the service has a single endpoint hosted at http://localhost:8000/HelloService. Which code segment should you use?

    • A.

      WebServiceHost svcHost = new WebServiceHost(typeof(HelloService)); svcHost.AddServiceEndpoint(typeof(IHelloService), new WebHttpBinding(WebHttpSecurityMode.None), "http://localhost:8000/HelloService"); return svcHost;

    • B.

      Uri baseAddress = new Uri("http://localhost:8000"); WebServiceHost svcHost = new WebServiceHost(typeof(HelloService), baseAddress); svcHost.AddServiceEndpoint(typeof(IHelloService), new WebHttpBinding(WebHttpSecurityMode.None), "HelloService"); return svcHost;

    • C.

      WebServiceHost svcHost = new WebServiceHost(new HelloService()); svcHost.AddServiceEndpoint(typeof(IHelloService), new WebHttpBinding(WebHttpSecurityMode.None), "http://localhost:8000/HelloService"); retumn svcHost

    • D.

      Uri baseAddress = new Uri("http://localhost:8000/"); WebServiceHost svcHost = new WebServiceHost(new HelloService(), baseAddress); svcHost.AddServiceEndpoint(typeof(IHelloService), new WebHttpBinding(WebHttpSecurityMode.None), "HelloService"); retumn svcHost;

    Correct Answer
    B. Uri baseAddress = new Uri("http://localhost:8000"); WebServiceHost svcHost = new WebServiceHost(typeof(HelloService), baseAddress); svcHost.AddServiceEndpoint(typeof(IHelloService), new WebHttpBinding(WebHttpSecurityMode.None), "HelloService"); return svcHost;
    Explanation
    The correct code segment to implement the CreateHost method is:

    Uri baseAddress = new Uri("http://localhost:8000");
    WebServiceHost svcHost = new WebServiceHost(typeof(HelloService), baseAddress);
    svcHost.AddServiceEndpoint(typeof(IHelloService),
    new WebHttpBinding(WebHttpSecurityMode.None),
    "HelloService");
    return svcHost;

    This code segment creates a new instance of the WebServiceHost class, passing in the type of the HelloService class and the base address. It then adds a service endpoint for the IHelloService contract using a WebHttpBinding with no security. The endpoint address is set to "HelloService". Finally, it returns the created WebServiceHost instance. This configuration ensures that the service is hosted at http://localhost:8000/HelloService.

    Rate this question:

  • 16. 

    You are building a client for a Windows Communication Foundation (WCF) service. You need to create a proxy to consume this service. Which class should you use?

    • A.

      ChannelFactory

    • B.

      ServiceHost

    • C.

      ClientRuntime

    • D.

      CommunicationObject

    Correct Answer
    A. ChannelFactory
    Explanation
    The correct answer is ChannelFactory. In WCF, a ChannelFactory is used to create a channel that can be used to communicate with a service. It provides methods to create a channel of a specified type and configure the channel's behavior. The ChannelFactory class is typically used on the client side to create a proxy that can consume the service.

    Rate this question:

  • 17. 

    You are working with a Windows Communication Foundation (WCF) client application that has a generated proxy named SampleServiceProxy. When the client application is executing, in line 04 of the following code, the channel faults (Line numbers are included for reference only.)      01 SampleServiceProxy proxy = new SampleServiceProxy(); 02 try 03 { 04     proxy.ProcessInvoice(invoice); 05 } 06 catch 07 { 08     if(proxy.State == CommunicationState.Faulted) 09     { 10         ... 11     } 12 } 13 proxy.UpdateCustomer(customer); You need to return proxy to a state in which it can successfully execute the call in line 13. Which code segment should you use at line 10?

    • A.

      Proxy.Close();

    • B.

      Proxy = new SampleServiceProxy();

    • C.

      Proxy.Abort();

    • D.

      Proxy.Open();

    Correct Answer
    B. Proxy = new SampleServiceProxy();
    Explanation
    At line 10, the code segment "proxy = new SampleServiceProxy();" should be used. This code segment creates a new instance of the SampleServiceProxy, effectively resetting the proxy to a state where it can successfully execute the call in line 13.

    Rate this question:

  • 18. 

    A Windows Communication Foundation (WCF) service has a callback contract. You are developing a client application that will call this service. You must ensure that the client application can interact with the WCF service. What should you do?

    • A.

      On the OperationContractAttribute, set the AsyncPattern property value to true.

    • B.

      On the OperationContractAttribute, set the ReplyAction property value to the endpoint address of the client.

    • C.

      On the client, create a proxy derived from DuplexClientBase.

    • D.

      On the client, use GetCallbackChannel.

    Correct Answer
    C. On the client, create a proxy derived from DuplexClientBase.
    Explanation
    Creating a proxy derived from DuplexClientBase on the client allows the client application to interact with the WCF service. DuplexClientBase provides support for duplex communication, which means that both the client and the service can send messages to each other. This is necessary when using a callback contract, as the service needs to be able to send messages back to the client. By creating a proxy derived from DuplexClientBase, the client application can establish a connection with the service and receive callback messages.

    Rate this question:

  • 19. 

    You are creating a Windows Communication Foundation (WCF) service. You have the following requirements: Messages must be sent over TCP The service must support transactions. Messages must be encoded using a binary encoding Messages must be secured using Windows stream-based security. You need to implement a custom binding for the service. In which order should the binding stack be configured?

    • A.

      TcpTransport, windowsStreamSecurity, transactionFlow, binaryMessageEncoding

    • B.

      TransactionFlow, binaryMessageEncoding, windowsStreamSecurity, tcpTransport

    • C.

      WindowsStreamSecurity, tcpTransport, binaryMessageEncoding, transactionFlow

    • D.

      BinaryMessageEncoding, transactionFlow, tcpTransport, windowsStreamSecurity

    Correct Answer
    B. TransactionFlow, binaryMessageEncoding, windowsStreamSecurity, tcpTransport
    Explanation
    The correct order for configuring the binding stack is transactionFlow, binaryMessageEncoding, windowsStreamSecurity, and tcpTransport. This order ensures that transactions are supported, messages are encoded using a binary encoding, messages are secured using Windows stream-based security, and messages are sent over TCP.

    Rate this question:

  • 20. 

    A Windows Communication Foundation (WCF) client configuration file contains the following XML segment in the system.serviceModel element. <client>     <endpoint address="net.tcp://server/ContosoService"         binding="netTcpBinding"         contract="Contoso.IContosoService"         name="netTcp"/>     <endpoint address="net.pipe://localhost/ContosoService"         binding="netNamedPipeBinding"         contract="Contoso.IContosoService"         name="netPipe" /> </client> You need to create a channel factory that can send messages to the endpoint listening at net.pipe://localhost/ContosoService. Which code segment should you use?

    • A.

      ChannelFactory factory = new ChannelFactory("Contoso.IContoso");

    • B.

      ChannelFactory factory = new ChannelFactory("netNamedPipeBinding");

    • C.

      ChannelFactory factory = new ChannelFactory("netPipe");

    • D.

      ChannelFactory factory = new ChannelFactory("net.pipe//localhost/ContosoService");

    Correct Answer
    C. ChannelFactory factory = new ChannelFactory("netPipe");
    Explanation
    The correct answer is "ChannelFactory factory = new ChannelFactory("netPipe");". This is because the endpoint in the client configuration file has the name attribute set to "netPipe", so when creating the channel factory, we need to pass the same name to match the endpoint.

    Rate this question:

  • 21. 

    A Windows Communication Foundation (WCF) solution uses the following contracts. (Line numbers are included for reference only.) 01 [ServiceContract(CallbackContract=typeof(INameService))] 02 public interface IGreetingService 03 { 04     [OperationContract] 05     string GetMessage(); 06 } 07 08 [ServiceContract] 09 public interface INameService 10 { 11     [OperationContract] 12     string GetName(); 13  } When the client calls GetMessage on the service interface, the service calls GetName on the client callback. In the client, the class NameService implements the callback contract. The client channel is created as follows: 22 InstanceContext callbackContext = new InstanceContext(new NameService("client")); 23 ... 24 ... 25 DuplexChannelFactory<IGreetingService> factory = new DuplexChannelFactory<IGreetingService>(typeof(NameService), binding, address); 26 IGreetingService greetingService = factory.CreateChannel(); You need to ensure that the service callback is processed by the instance of NameService. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution.  Choose two.)

    • A.

      Change line 25 to the following code segment: DuplexChannelFactory factory = new DuplexChannelFactory(callbackContext, binding, address);

    • B.

      Change line 26 to the following code segment: IGreetingService greetingServicefactory = CreateChannel(callbackContext);

    • C.

      Add the following code segment after line 26: callbackContext.IncomingChannels.Add((IDuplexChannel)greetingService);

    • D.

      Add the following code segment after line 26: callbackContext.OutgoingChannels.Add((IDuplexChannel)greetingService);

    Correct Answer(s)
    A. Change line 25 to the following code segment: DuplexChannelFactory factory = new DuplexChannelFactory(callbackContext, binding, address);
    B. Change line 26 to the following code segment: IGreetingService greetingServicefactory = CreateChannel(callbackContext);
    Explanation
    The first possible way to achieve the goal is to change line 25 to the code segment "DuplexChannelFactory factory = new DuplexChannelFactory(callbackContext, binding, address);". This ensures that the callback context is passed to the DuplexChannelFactory, allowing the service callback to be processed by the instance of NameService.

    The second possible way is to change line 26 to the code segment "IGreetingService greetingServicefactory = CreateChannel(callbackContext);". This creates the channel using the CreateChannel method with the callback context parameter, ensuring that the service callback is processed by the instance of NameService.

    Rate this question:

  • 22. 

    A Windows Communication Foundation (WCF) solution exposes the following contract over an HTTP connection. [ServiceContract] public interface IDataService {     [OperationContract]     string GetData(); } Existing clients are making blocking calls to GetData.  Calls to GetData take five seconds to complete. You need to allow new clients to issue non-blocking calls to get the data, without breaking any existing clients. What should you do?

    • A.

      Replace the service interface with the following interface and implement the new methods. [ServiceContract] public interface IDoSomething { [OperationContract] string DoLongOperation(); [OperationContract(AsyncPattern = true)] IAsyncResult BeginDoLongOperation(); [OperationContract(AsyncPattern = true)] string EndDoLongOperation(IAsyncResult result); }

    • B.

      Replace the service interface with the following interface and implement the new methods. [ServiceContract] public interface IDoSomething { [OperationContract(AsyncPattern = true)] IAsyncResult BeginDoLongOperation(); [OperationContract(AsyncPattern = true)] string EndDoLongOperation(IAsyncResult result); }

    • C.

      Generate a proxy class with asynchronous methods and use it for the new clients.

    • D.

      Add a new endpoint to the service that uses a full-duplex binding and use it for the new clients.

    Correct Answer
    C. Generate a proxy class with asynchronous methods and use it for the new clients.
    Explanation
    The correct answer is to generate a proxy class with asynchronous methods and use it for the new clients. By generating a proxy class with asynchronous methods, new clients can issue non-blocking calls to get the data. This means that the new clients will not have to wait for the GetData call to complete before continuing with their operations. This solution allows for concurrent execution of multiple operations, improving the overall performance and responsiveness of the system without affecting the existing clients.

    Rate this question:

  • 23. 

    A Windows Communication Foundation (WCF) service implements the following contract. (Line numbers are included for reference only.) 01 [ServiceContract] 02 public interface IDataAccessService 03 { 04     [OperationContract] 05     void PutMessage(string message); 06     ... 07     [OperationContract] 08     [FaultContract(typeof(TimeoutFaultException))] 09     [FaultContract(typeof(FaultException))] 10     string SearchMessages(string search); 11 } The implementation of the SearchMessages method throws TimeoutFaultException exceptions for database timeouts. The implementation of the SearchMessages method also throws an Exception for any other issue it encounters while processing the request. These exceptions are received on the client side as generic FaultException exceptions. You need to implement the error handling code for SearchMessages and create a new channel on the client only if the channel faults. What should you do?

    • A.

      Catch and handle both TimeoutFaultException and FaultException.

    • B.

      Catch both TimeoutFaultException and FaultException. Create a new channel in both cases.

    • C.

      Catch and handle TimeoutFaultException. Catch FaultException and create a new channel.

    • D.

      Catch and handle FaultException. Catch TimeoutFaultException and create a new channel.

    Correct Answer
    C. Catch and handle TimeoutFaultException. Catch FaultException and create a new channel.
    Explanation
    The correct answer is to catch and handle TimeoutFaultException and catch FaultException and create a new channel. This is because the implementation of the SearchMessages method throws TimeoutFaultException exceptions for database timeouts and throws an Exception for any other issue. These exceptions are received on the client side as generic FaultException exceptions. Therefore, it is necessary to catch and handle TimeoutFaultException separately and create a new channel if a FaultException is caught.

    Rate this question:

  • 24. 

    You are consuming a Windows Communication Foundation (WCF) service in an ASP. NET Web application. The service interface is defined as follows: [ServiceContract] public interface ICatalog {     [OperationContract]     [WebGet(UriTemplate="/Catalog/Items/{id}", ResponseFormat=WebMessageFormat.Json)]     string RetrieveItemDescription(int id); } The service is hosted at Catalogsvc. You need to call the service using jQuery to retrieve the description of an item as indicated by a variable named itemId. Which code segment should you use?

    • A.

      $get(String.format("/Catalogsvc/Catalog/Items/id{0}", itemId) null, function (data) { ... }, javascript");

    • B.

      $get(String.format("/Catalogsvc/Catalog/Items/{0}", itemId), null, function (data) { ... }, "json");

    • C.

      $get(String.format("/Catalogsvc/Catalog/Items/{0}", itemld), null, function (data) { ... }, "xml");

    • D.

      $get(String.format("/Catalogsvc/Catalog/Items/id{0}", itemld), null, function (data) { ... }, "json");

    Correct Answer
    B. $get(String.format("/Catalogsvc/Catalog/Items/{0}", itemId), null, function (data) { ... }, "json");
    Explanation
    The correct code segment to use is $get(String.format("/Catalogsvc/Catalog/Items/{0}", itemId), null, function (data) {
    ...
    }, "json"). This is because the RetrieveItemDescription method in the service interface is decorated with the [WebGet] attribute, which specifies a UriTemplate of "/Catalog/Items/{id}". This means that the URL to retrieve the item description should be in the format "/Catalogsvc/Catalog/Items/{id}", where {id} is the id of the item. The code segment correctly uses String.format to substitute the {0} placeholder with the value of the itemId variable. The "json" parameter in the code segment specifies that the response format should be JSON.

    Rate this question:

  • 25. 

    You are consuming a Windows Communication Foundation (WCF) service. The service interface is defined as follows: [DataContract(Namespace = ''] public class Item { } [ServiceContract(Namespace = '')] public interface Catalog {      [OperationContract]           [WebInvoke(Method="POST", UriTemplate="{Item}")]       Item UpdateItem(Item item); } The client application receives a WebResponse named response with the response from the service. You need to deserialize this response into a strongly typed object representing the return value of the method. Which code segment should you use?

    • A.

      DataContractSerializer s = new DataContractSerializer(typeof(Item)); Item item = s.ReadObject(response.GetResponseStream()) as Item;

    • B.

      BinaryFormatter f = new BinaryFormatter(); Item item = f.Deserialize(response.GetResponseStream() as Item;

    • C.

      XmlDictionaryReader r = JsonReaderWriterFactory.CreateJsonReader(response.GetResponseStream(), XmlDictionaryReaderQuotas.Max); DataContractSerializer s = new DataContractSerializer(typeof(Item)); Item item = s.ReadObject(r) as Item;

    • D.

      DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(Item)); Item item = s.ReadObject(response.GetResponseStream()) as Item;

    Correct Answer
    A. DataContractSerializer s = new DataContractSerializer(typeof(Item)); Item item = s.ReadObject(response.GetResponseStream()) as Item;
    Explanation
    The correct code segment to deserialize the response into a strongly typed object representing the return value of the method is:

    DataContractSerializer s = new DataContractSerializer(typeof(Item));
    Item item = s.ReadObject(response.GetResponseStream()) as Item;

    This code uses the DataContractSerializer to deserialize the response stream into an object of type Item. The ReadObject method is used to read and deserialize the stream, and the result is cast to the Item type.

    Rate this question:

  • 26. 

    A Windows Communication Foundation (WCF) application exposes a service as a SOAP endpoint for consumption by cross-platform clients. During integration testing, you find that one of the clients is not generating the correct messages to the WCF application. In order to debug the issue and fix the communication, you need to configure the service to log messages received from the client. What should you do?

    • A.

      Set an etwTracking behavior on the service and configure a listener for the System.ServiceModel trace source.

    • B.

      Set an etwTracking behavior on the service and configure a listener for the System.ServiceModel.MessageLogging trace source.

    • C.

      Enable messageLogging in the System.ServiceModel diagnostics element configuration and configure a listener for the System.ServiceModel.MessageLogging trace source.

    • D.

      Enable messageLogging in the System.ServiceModel diagnostics element configuration and configure a listener for the System.ServiceModel trace source.

    Correct Answer
    C. Enable messageLogging in the System.ServiceModel diagnostics element configuration and configure a listener for the System.ServiceModel.MessageLogging trace source.
    Explanation
    To debug and fix the communication issue, the correct approach is to enable messageLogging in the System.ServiceModel diagnostics element configuration. This allows the service to log the messages received from the client. Additionally, a listener needs to be configured for the System.ServiceModel.MessageLogging trace source to capture and analyze the logged messages.

    Rate this question:

  • 27. 

    A Windows Communication Foundation (WCF) service interacts with the database of a workflow engine. Data access authorization is managed by the database, which raises security exceptions if a user is unauthorized to access it. You need to ensure that the application transmits the exceptions raised by the database to the client that is calling the service. Which behavior should you configure and apply to the service?

    • A.

      Routing

    • B.

      ServiceDebug

    • C.

      ServiceSecurityAudit

    • D.

      WorkflowUnhandledException

    Correct Answer
    B. ServiceDebug
    Explanation
    The correct answer is "serviceDebug". By configuring and applying the "serviceDebug" behavior to the service, the application will transmit the exceptions raised by the database to the client calling the service. This behavior allows for debugging and troubleshooting purposes by providing detailed information about any exceptions that occur during the service operation.

    Rate this question:

  • 28. 

    A Windows Communication Foundation (WCF) client application is consuming an RSS syndication feed from a blog. You have a SyndicationFeed variable named feed. The application iterates through the items as follows. (Line numbers are included for reference only.) 01 foreach (SyndicationItem item in feed.Items) 02 { 03 } You need to display the content type and body of every syndication item to the console. Which two lines of code should ou insert between lines 02 and 03?

    • A.

      ConsoleWriteLine(item.Content.Type); ConsoleWriteLine(((TextSyndicationContent)item.Content).Text);

    • B.

      Console.WriteLine(item.Content.GetType()); Console.WriteLine(((TextSyndicationContent)item.Content).Text);

    • C.

      Console.WriteLine(item.Content.Type); Console.WriteLine(item.Content.ToString());

    • D.

      Console.WriteLine(item.Content.GetType()); Console.WriteLine(item.Content.ToString());

    Correct Answer
    A. ConsoleWriteLine(item.Content.Type); ConsoleWriteLine(((TextSyndicationContent)item.Content).Text);
    Explanation
    The correct answer is to insert the following two lines of code between lines 02 and 03:

    Console.WriteLine(item.Content.Type);
    Console.WriteLine(((TextSyndicationContent)item.Content).Text);

    These lines of code will display the content type and body of each syndication item to the console.

    Rate this question:

  • 29. 

    You are creating a Windows Communication Foundation (WCF) service to process orders. The data contract for the order is defined as follows: [DataContract] public class Order {     [DataMember]     public string CardHolderName { get; set; }     [DataMember]     public string CreditCardNumber { get; set; } } You have the following requirements: Enable the transmission of the contents of Order from the clients to the service. Ensure that the contents of CreditCardNumber are not sent across the network in clear text. Ensure that the contents of CreditCardNumber are accessible by the service to process the order. You need to implement the service to meet these requirements. What should you do?

    • A.

      Add a DataProtectionPermission attribute to the CreditCardNumber property and set the ProtectData property to true.

    • B.

      Convert the DataContract to a MessageContract and set the ProtectionLevel property to SignAndEncrypt.

    • C.

      Change the data type of CreditCardNumber from string to SecureString.

    • D.

      Implement the CreditCardNumber property getter and setter In the setter, run the value of the CreditCardNumber through the MD5CryptoServiceProvider class TransformBlock method.

    Correct Answer
    B. Convert the DataContract to a MessageContract and set the ProtectionLevel property to SignAndEncrypt.
  • 30. 

    You are creating a Windows Communication Foundation (WCF) service that accepts messages from clients when they are started. The message is defined as follows: [MessageContract] public class Agent {     public string CodeName { get; set; }     public string SecretHandshake { get; set; } } You have the following requirements: The CodeName property must be sent in clear text. The service must be able to verify that the property value was not changed after being sent by the client. The SecretHandshake property must not be sent in clear text and must be readable by the service. What should you do?

    • A.

      Add a MessageBodyMember attribute to the CodeName property and set the ProtectionLevel to Sign. Add a MessageBodyMember attribute to the SecretHandshake property and set the ProtectionLevel to EncryptAndSign.

    • B.

      Add a DataProtectionPermission attribute to the each property and set the ProtectData property to true.

    • C.

      Add an xmlText attribute to the CodeName property and set the DataType property to Signed. Add a PasswordPropertyText attribute to the SecretHandshake property and set its value to true.

    • D.

      Add an ImmutableObject attribute to the CodeName property and set its value property to true. Add a Browsable attribute to the SecretHandshake property and set its value to false.

    Correct Answer
    A. Add a MessageBodyMember attribute to the CodeName property and set the ProtectionLevel to Sign. Add a MessageBodyMember attribute to the SecretHandshake property and set the ProtectionLevel to EncryptAndSign.
    Explanation
    To meet the requirements, the CodeName property needs to be sent in clear text and the service needs to be able to verify that the value was not changed. Therefore, the CodeName property should have a MessageBodyMember attribute with a ProtectionLevel set to Sign. This will ensure that the property is sent in clear text and that the service can verify its integrity.

    Similarly, the SecretHandshake property needs to be sent in an encrypted format and readable by the service. Therefore, it should have a MessageBodyMember attribute with a ProtectionLevel set to EncryptAndSign. This will ensure that the property is encrypted and can be decrypted by the service.

    Rate this question:

  • 31. 

    A Windows Communication Foundation (WCF) client uses the following service contract. (Line numbers are included for reference only.) 01 [ServiceContract] 02 public interface IService 03 { 04     [OperationContract] 05     string Operation1(); 06     [OperationContract] 07     string Operation2(); 08 } You need to ensure that all calls to Operation1 and Operation2 from the client are encrypted and signed. What should you do?

    • A.

      Set the ProtectionLevel property in line 01 to EncryptAndSign.

    • B.

      Set the ProtectionLevel property in line 04 and line 06 to Sign.

    • C.

      Add a SecurityCriticalAttribute ror each operation.

    • D.

      Add a SecunitySafeCriticalAttribute for each operation.

    Correct Answer
    A. Set the ProtectionLevel property in line 01 to EncryptAndSign.
    Explanation
    Setting the ProtectionLevel property in line 01 to EncryptAndSign will ensure that all calls to Operation1 and Operation2 from the client are encrypted and signed. This means that the data being transmitted will be encrypted to protect its confidentiality and integrity, and it will also be signed to ensure that it has not been tampered with during transmission. This is the appropriate action to take in order to meet the requirement of encrypting and signing all calls to these operations.

    Rate this question:

  • 32. 

    You are creating a Windows Communication Foundation (WCF) service that implements the following service contract. [ServiceContract] public interface IOrderProcessing {     [OperationContract]     void ApproveOrder(int id); } You need to ensure that only users with the Manager role can call the ApproveOrder method. What should you do?

    • A.

      In the method body, check the Rights PosessesProperty property to see if it contains Manager

    • B.

      Add a PrincipalPermission attribute to the method and set the Roles property to Manager

    • C.

      Add a SecurityPermission attribute to the method and set the SecurityAction to Demand

    • D.

      In the method body, create a new instance of WindowsClaimSet. Use the FindClaims method to locate a claimType named Role with a right named Manager

    Correct Answer
    B. Add a PrincipalPermission attribute to the method and set the Roles property to Manager
    Explanation
    The correct answer is to add a PrincipalPermission attribute to the method and set the Roles property to Manager. This will ensure that only users with the Manager role can call the ApproveOrder method. The PrincipalPermission attribute allows you to specify the roles that are required to access the method, in this case, only users with the Manager role.

    Rate this question:

  • 33. 

    You are developing a Windows Communication Foundation (WCF) service. The service needs to access out-of-process resources. You need to ensure that the service accesses these resources on behalf of the originating caller. What should you do?

    • A.

      Set the value of ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel to TokenlmpersonationLevel.Impersonation

    • B.

      Set the value of ServiceSecurityContext.Current.Windowsldentity.ImpersonationLevel to TokenlmpersonationLevel.Delegation

    • C.

      Set the PrincipalPermissionAttribute on the service contract and update the binding attribute in the endpoint element of the configuration file to wsHttpBinding

    • D.

      Set the PnncipalPermissionAttribute on the service contract and update the bindingConfiguration attribute in the endpoint element of the configuration file to wsHttpBinding

    Correct Answer
    B. Set the value of ServiceSecurityContext.Current.Windowsldentity.ImpersonationLevel to TokenlmpersonationLevel.Delegation
    Explanation
    Setting the value of ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel to TokenImpersonationLevel.Delegation allows the service to access out-of-process resources on behalf of the originating caller. Delegation impersonation level allows the service to delegate the caller's identity to another resource, such as a database or file server, allowing the service to access those resources using the caller's identity. This ensures that the service can access the necessary resources while still maintaining the security and permissions of the originating caller.

    Rate this question:

  • 34. 

    A Windows Communication Foundation (WCF) service exposes two operations: OpA and OpB. OpA needs to execute under the client's identity, and OpB needs to execute under the service's identity. You need to configure the service to run the operations under the correct identity. What should you do?

    • A.

      Set the ImpersonateCallerForAllOperations property of the service's ServiceAuthorizationBehavior to true. Apply an OperationBehavior attribute to OpA and set the Impersonation property to ImpersonationOption.Required. Apply an OperationBehavior attribute to OpB and set the Impersonation property to ImpersonationOption.Allowed.

    • B.

      Set the ImpersonateCallerForAllOperations property of the service's ServiceAuthorizationBehavior to true. Apply an OperationBehavior attribute to OpA and set the Impersonation property to ImpersonationOption.Allowed. Apply an OperationBehavior attribute to OpB and set the Impersonation property to ImpersonationOption.NotAllowed.

    • C.

      Set the ImpersonateCallerForAllOperations property of the service's ServiceAuthorizationBehavior to false. Apply an OperationBehavior attribute to OpA and set the Impersonation property to ImpersonationOption.Allowed. Apply an OperationBehavior attribute to OpB and set the Impersonation property to ImpersonationOption.NotAllowed.

    • D.

      Set the ImpersonateCallerForAllOperations property of the service's ServiceAuthorizationBehavior to false. Apply an OperationBehavior attribute to OpA and set the Impersonation property to lmpersonationOption.Required. Apply an OperationBehavior attribute to OpB and set the Impersonation property to ImpersonationOption.Allowed.

    Correct Answer
    C. Set the ImpersonateCallerForAllOperations property of the service's ServiceAuthorizationBehavior to false. Apply an OperationBehavior attribute to OpA and set the Impersonation property to ImpersonationOption.Allowed. Apply an OperationBehavior attribute to OpB and set the Impersonation property to ImpersonationOption.NotAllowed.
    Explanation
    The correct answer is to set the ImpersonateCallerForAllOperations property of the service's ServiceAuthorizationBehavior to false, apply an OperationBehavior attribute to OpA and set the Impersonation property to ImpersonationOption.Allowed, and apply an OperationBehavior attribute to OpB and set the Impersonation property to ImpersonationOption.NotAllowed. This configuration ensures that OpA executes under the client's identity and OpB executes under the service's identity. By setting ImpersonateCallerForAllOperations to false, the service will not impersonate the caller for all operations. The OperationBehavior attributes on OpA and OpB further specify the impersonation options for each operation.

    Rate this question:

  • 35. 

    A Windows Communication Foundation (WCF) service that handles corporate accounting must be changed to comply with government regulations of auditing and accountability. You need to configure the WCF service to execute under the Windows logged-on identity of the calling application. What should you do?

    • A.

      Within the service configuration, add a ServiceAuthorization behavior to the service, and set ImpersonateCallerForAllOperations to true.

    • B.

      Within the service configuration, add a ServiceAuthenticationManager behavior to the service, and set ServiceAuthenticationManagerType to Impersonate.

    • C.

      Within the service configuration, add a serviceSecurityAudit behavior to the service, and set serviceAuthorizationAuditLevel to SuccessOrFailure.

    • D.

      Within the service configuration, add a ServiceCredentials behavior to the service, and set type to Impersonate.

    Correct Answer
    A. Within the service configuration, add a ServiceAuthorization behavior to the service, and set ImpersonateCallerForAllOperations to true.
    Explanation
    To configure the WCF service to execute under the Windows logged-on identity of the calling application, you need to add a ServiceAuthorization behavior to the service configuration and set ImpersonateCallerForAllOperations to true. This will allow the service to impersonate the caller's identity for all operations, ensuring that the service executes with the appropriate permissions and complies with government regulations of auditing and accountability.

    Rate this question:

  • 36. 

    You have a secured Windows Communication Foundation (WCF) service. You need to track unsuccessful attempts to access the service. What should you do?

    • A.

      Set the authorizationManagerType attribute of the serviceAuthorization behavior to Message.

    • B.

      Set the includeExceptionDetailslnFaults attribute of the serviceDebug behavior to true.

    • C.

      Set the Mode attribute of the security configuration element to Message.

    • D.

      Set the messageAuthenticationAuditLevel attribute of the serviceSecurityAudit behavior to Failure.

    Correct Answer
    D. Set the messageAuthenticationAuditLevel attribute of the serviceSecurityAudit behavior to Failure.
    Explanation
    The correct answer is to set the messageAuthenticationAuditLevel attribute of the serviceSecurityAudit behavior to Failure. This will enable auditing of authentication failures for the WCF service. By setting the messageAuthenticationAuditLevel to Failure, the service will track and log unsuccessful attempts to access the service, providing valuable information for security analysis and troubleshooting.

    Rate this question:

  • 37. 

    A Windows Communication Foundation (WCF) solution uses the following contract to share a message across its clients. (Line numbers are included for reference only.) 01 [ServiceContract] 02 public interface ITeamMessageService 03 { 04     [OperationContract] 05     string GetMessage(); 07    [OperationContract] 08     void PutMessage(string message); 09 } The code for the service class is as follows: 10 public class TeamMessageService: ITeamMessageService 11 { 12     Guid key = Guid.NewGuid(); 13     string message = "Today's Message"; 14     public string GetMessage() 15     { 16         return stringFormat("Message:{0} Key:{1}", 17             message, key); 18   } 19     public void PutMessage(string message) 20     { 21         this.message = message; 22     } 23 } The service is self-hosted. The hosting code is as follows: 24 ServiceHost host = new ServiceHost(typeof(TeamMessageService)); 25 BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None): 26 host.AddServiceEndpoint(MyApplication.ITeamMessageService, binding, "http://localhost:12345"); 27 host.Open(); You need to ensure that all clients calling GetMessage will retrieve the same string, even if the message is updated by clients calling PutMessage. What should you do

    • A.

      Add the following attribute to the TeamMessageService class, before line 10. [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

    • B.

      Add the following attribute to the TeamMessageService class, before line 10. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] Then change the binding definition on the service at line 25, and on the client to the following WSHttpBinding binding = new WSHttpBinding(SecurityMode.None); binding.ReliableSession.Enabled = true;

    • C.

      Pass a service instance to the instancing code in line 24, as follows. ServiceHost host = new ServiceHost(new TeamMessageService());

    • D.

      Redefine the message string in line 13, as follows static string message = "Today's Message"; Then change the implementation of PutMessage in lines 19-22 to the following public void PutMessage(string message) { TeamMessageServiceMessage.PutMessage; }

    Correct Answer
    A. Add the following attribute to the TeamMessageService class, before line 10. [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    Explanation
    Adding the [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] attribute to the TeamMessageService class ensures that only one instance of the service class is created and shared among all clients. This means that all clients calling GetMessage will retrieve the same string, even if the message is updated by clients calling PutMessage.

    Rate this question:

  • 38. 

    A Windows Communication Foundation (WCF) solution exposes the following service over a TCP binding. (Line numbers are included for reference only.) 01 [ServiceContract] 02 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] 03 public class DataAccessService 04 { 05     [OperationContract] 06     public void PutMessage(string message) 07     { 08         MessageDatabase.PutMessage(message); 09     } 10     [OperationContract] 11     pubic string[] SearchMessages(string search) 12     { 13         return MessageDatabase.SearchMessages(search); 14     } 15 } MessageDatabase supports a limited number of concurrent executions of its methods. You need to change the service to allow up to the maximum number of executions of the methods of MessageDatabase. This should be implemented without preventing customers from connecting to the service. What should you do?

    • A.

      Change the service behavior as follows. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]

    • B.

      Change the service behavior as follows. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.PerSession)]

    • C.

      Add a throttling behavior to the service, and configure the maxConcurrentCalls.

    • D.

      Add a throttling behavior to the service, and configure the maxConcurrentSessions.

    Correct Answer
    C. Add a throttling behavior to the service, and configure the maxConcurrentCalls.
    Explanation
    To allow up to the maximum number of executions of the methods of MessageDatabase without preventing customers from connecting to the service, a throttling behavior needs to be added to the service and the maxConcurrentCalls should be configured. This will limit the number of concurrent calls to the service and ensure that the maximum number of executions of the methods is not exceeded.

    Rate this question:

  • 39. 

    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)]

    Correct Answer
    A. Define binding2 as follows: WS2007HttpBinding binding2 = new WS2007HttpBinding(SecurityMode.None); Configure binding2 as follows: binding2.ReliableSession.Enabled = true;
  • 40. 

    A Windows Communication Foundation (WCF) solution uses the following contract: [ServiceContract(SessionMode=SessionMode.Allowed)] public interface IMyService {     [OperationContract(IsTerminating=false)]     void Initialize();     [OperationContract(IsInitiating=false)]     void DoSomething();     [OperationContract(IsTerminating=true)]     void Terminate(); } You need to change this interface so that: lnitialize is allowed to be called at any time before Terminate is called. DoSomething is allowed to be called only after Initialize is called, and not allowed to be called after Terminate is called. Terminate will be allowed to be called only after Initalize is called. Which two actions should you perform? (Each correct answer presents part of the sdution. Choose two)

    • A.

      Change the ServiceContract attribute of the IMyService interface to the following. [ServiceContract(SessionMode=SessionMode.Required)]

    • B.

      Change the ServiceContract attrbute of the IMyService interface to the following [ServiceContract(SessionMode=SessionMode.Allowed)]

    • C.

      Change the OperationContract attribute of the Initialize operation to the following. [OperationContract(IsInitiating = true, IsTerminating = false)]

    • D.

      Change the OperationContract attribute of the Terminate operation to the following [OperationContract(IsInitiating = false, IsTerminating = true)]

    Correct Answer(s)
    A. Change the ServiceContract attribute of the IMyService interface to the following. [ServiceContract(SessionMode=SessionMode.Required)]
    D. Change the OperationContract attribute of the Terminate operation to the following [OperationContract(IsInitiating = false, IsTerminating = true)]
    Explanation
    The correct answer is to change the ServiceContract attribute of the IMyService interface to [ServiceContract(SessionMode=SessionMode.Required)] and to change the OperationContract attribute of the Terminate operation to [OperationContract(IsInitiating = false, IsTerminating = true)].

    By changing the ServiceContract attribute to SessionMode.Required, it ensures that a session is required for all operations in the contract. This means that the Initialize operation can be called at any time before Terminate is called.

    By changing the OperationContract attribute of the Terminate operation to IsInitiating = false and IsTerminating = true, it ensures that Terminate can only be called after Initialize is called. Additionally, by setting IsTerminating = true, it ensures that Terminate is the last operation that can be called in the session.

    Rate this question:

  • 41. 

    A Windows Communication Foundation (WCF) client and service share the following service contract interface: [ServiceContract] public interface IContosoService {     [OperationContract]     void SavePerson(Person person); } They also use the following binding: NetTcpBinding binding = new NetTcpBinding() { TransactionFlow = true }; The client calls the service with the following code: using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) {     IContosoService client = factory.CreateChannel();     client.SavePerson(person);     Console.WriteLine(Transaction.Current.TransactionInformation.DistributedIdentifier);     ts.Complete(); } The service has the following implementation for SavePerson: public void IContosoService.SavePerson(Person person) {     person.Save();     Console.WriteLine(Transaction.Current.TransactionInformation.DistributedIdentifier); } The distributed identifiers do not match on the client and the server. You need to ensure that the client and server enlist in the same distributed transaction. What should you do?

    • A.

      Add the following attributes to the SavePerson operation on IContosoService. [OperationBehavior(TransactionScope.Required = true)] [TransactionFlow(TransactionFlowOption.Mandatory)]

    • B.

      Add the following attributes to the SavePerson operation on lContosoService [TransactionFlow(TransactionFlowOption.Mandatory)] [OperationBehavior(TransactionScope.Required = true)]

    • C.

      Add the following attribute to the SavePerson operation on lContosoService [OperationBehavior(TransactionScope.Required = true)] Add the following attribute to the implementation of SavePerson. [TransactionFlow(TransactionFlowOption.Allowed)]

    • D.

      Add the following attribute to the SavePerson operation on lContosoService [TransactionFlow(TransactionFlowOption.Allowed)] Add the following attribute to the implementation of SavePerson. [OperationBehavior(TransactionScope.Required = true)]

    Correct Answer
    D. Add the following attribute to the SavePerson operation on lContosoService [TransactionFlow(TransactionFlowOption.Allowed)] Add the following attribute to the implementation of SavePerson. [OperationBehavior(TransactionScope.Required = true)]
    Explanation
    The correct answer is to add the following attribute to the SavePerson operation on lContosoService: [TransactionFlow(TransactionFlowOption.Allowed)]. This allows the client and server to participate in the same distributed transaction. Additionally, the implementation of SavePerson should have the attribute [OperationBehavior(TransactionScope.Required = true)] to ensure the transaction is required for the operation.

    Rate this question:

  • 42. 

    A service implements the following contract. (Line numbers are included for reference only) 01 [ServiceContract(SessionMode = SessionMode.Required)] 02 public interface IContosoService 03 { 04     [OperationContract(IsOneWay = true, IsInitiating = true)] 05     void OperationOne(string value); 06 07     [OperationContract(IsOneWay = true, IsInitiating = false)] 08     void OperationTwo(string value); 09 } The service is implemented as follows: 10 class ContosoService: IContosoService 11 { 12     public void OperationOne(string value) {...} 13     ... 14     public void OperationTwo(string value) {...} 15 } ContosoService uses NetMsmqBinding to listen for messages. The queue was set up to use transactions for adding and removing messages. You need to ensure that OperationOne and OperationTwo execute under the same transaction context when they are invoked in the same session. What should you do?

    • A.

      Insert the following attribute to OperationOne on lContosoService [TransactionFlow(TransactionFlowOption.Mandatory)] Insert the following attribute to OperationTwo on IContosoService [TransactionFlow(TransactionFlowOption.Mandatory)]

    • B.

      Insert the following attribute to OperationOne on ContosoService [OperationBehavior(TransactonScopeRequired=true, TransactionAutoComplete=false)] Insert the following attribute to OperationTwo on ContosoService. [OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=true)]

    • C.

      Add the following XML segment to the application config file in the system serviceModel/bindings configuration section Then use the NetMsmqBinding named contosoTx to listen for messages from the clients.

    • D.

      Add the following XML segment to the application config file in the systemserviceModel/bindings configuration section. Then use the CustommiBinding named contosoTx to listen fcw messages from the clients.

    Correct Answer
    B. Insert the following attribute to OperationOne on ContosoService [OperationBehavior(TransactonScopeRequired=true, TransactionAutoComplete=false)] Insert the following attribute to OperationTwo on ContosoService. [OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=true)]
    Explanation
    The correct answer is to insert the [OperationBehavior(TransactonScopeRequired=true, TransactionAutoComplete=false)] attribute to OperationOne on ContosoService and insert the [OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=true)] attribute to OperationTwo on ContosoService. These attributes specify that both operations require a transaction scope and that OperationOne should not automatically complete the transaction while OperationTwo should. This ensures that both operations execute under the same transaction context when invoked in the same session.

    Rate this question:

  • 43. 

    A WCF service code is implemented as follows. (Line numbers are included for reference only) 01 [ServiceContract] 02 [ServiceBehavior(InstanceContextMode = 03 InstanceContextMode.Single)] 04 public class CalculatorService 05 { 06     [OperationContract] 07     public double Calculate(double op1, string op, double op2) 08     { 09     } 10 } You need to increase the rate by which clients get the required response from the service. What are two possble ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

    • A.

      Change the service behavior to the following: [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)]

    • B.

      Change the service behavior to the following. [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]

    • C.

      Require the clients use threads, the Parallel Task Library, or other mechanism to issue service calls in parallel.

    • D.

      Require the clients to use async operations when calling the senvice.

    Correct Answer(s)
    A. Change the service behavior to the following: [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)]
    B. Change the service behavior to the following. [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
    Explanation
    Changing the service behavior to [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)] allows multiple clients to access the service simultaneously, increasing the rate at which clients get the required response. This is because the service instance is shared among multiple clients, allowing them to execute concurrently. Similarly, changing the service behavior to [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)] creates a new service instance for each client request, allowing multiple clients to be served simultaneously and improving the response rate.

    Rate this question:

  • 44. 

    A Windows Communication Foundation (WCF) solution uses the following contracts. (Line numbers are included for reference only.) 01 [ServiceContract(CallbackContract=typeof(INameService))] 02 public interface IGreetingService 03 { 04     [OperationContract] 05     string GetMessage(); 06 } 07 [ServiceContract] 08 public interface INameService 09 { 10     [OperationContract] 11     string GetName(); 12 } The code that implements the IGreetingService interface is as follows: 20 public class GreetingService : IGreetingService 21{ 22     public string GetMessage() 23     { 24         INameService clientChannel = OperationContext.Current.GetCallbackChannel<INameService>(); 25         string clientName = clientChannel.GetName(); 26         return String.Format("Hello {0}", clientName); 27     } 28 } The service is self-hosted. The hosting code is as follows: 30 ServiceHost host = new ServiceHost(typeof(GreetingService)); 31 NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); 32 host.AddServiceEndpoint("MyApplication.IGreetingService", binding, "net.tcp//localhost:12345"); 33 host.Open(); The code that implements the lNameService interface is as follows: 40 class NameService : INameService 41 { 42     string name; 43     public NameService(string name) 44     { 45         this.name = name; 46     } 47     public string GetName() 48     { 49         return name; 50     } 51 } Currently, this code fails at runtime, and an InvalidOperationException is thrown at line 25. You need to correct the code so that the call from the service back to the client completes successfully. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

    • A.

      Change the service contract definition in line 01 as follows. [ServiceContract(CallbackContract = typeof(INameService), SessionMode = SessionMode.Required)]

    • B.

      Add the following attribute to the NameService class, before line 40. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]

    • C.

      Add the following attribute to the GreetingService class, before line 20. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]

    • D.

      Add the following attribute to the GreetingService class, before line 20. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

    Correct Answer(s)
    C. Add the following attribute to the GreetingService class, before line 20. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    D. Add the following attribute to the GreetingService class, before line 20. [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
    Explanation
    Adding the [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] attribute to the GreetingService class before line 20 allows the service to handle multiple requests concurrently and reenter the same operation if necessary. This ensures that the call from the service back to the client completes successfully without causing an InvalidOperationException at line 25. Similarly, adding the [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] attribute to the GreetingService class before line 20 also allows the service to handle multiple requests concurrently and resolves the runtime failure.

    Rate this question:

  • 45. 

    A Windows Communication Foundation (WCF) service has the following contract: [ServiceContract] public class ContosoService {     [OperationContract]     [TransactionFlow(TransactionFlowOption.Mandatory)]     [OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=false)]     void TxOp1(string value) {... };     [OperationContract(IsTerminating=true)]     [TransactionFlow(TransactionFlowOption.Mandatory)]     [OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=false)]     void TxOp2(string value)     {         ...         OperationContext.Current.SetTransactionComplete();     } } The service and the clients that call the service use NetTcpBinding with transaction flow enabled. You need to configure the service so that when TxOp1 and TxOp2 are invoked under the same client session, they run under the same transaction context. What should you do?

    • A.

      Update the service contract to read as follows. [ServiceContract(SessionMode=SessionMode.Required)] Add the following behavior to the service implementation [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]

    • B.

      Update the service contract to read as follows. [ServiceContract(SessionMode=SessionMode.Allowed)] Add the following behavior to the service implementation. [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ReleaseServiceInstanceOnTransactionComplete=false)]

    • C.

      Update the service contract to read as follows [ServiceContract(SessionMode=SessionMode.Allowed)] Add the followng behavior to the service implementation. [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]

    • D.

      Update the service contract to read as follows. [ServiceContract(SessionMode=SessionMode.Required)] Add the following behavior to the service implementation. [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]

    Correct Answer
    A. Update the service contract to read as follows. [ServiceContract(SessionMode=SessionMode.Required)] Add the following behavior to the service implementation [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
    Explanation
    The correct answer is to update the service contract to have SessionMode as Required and add the behavior to the service implementation with InstanceContextMode as PerSession. This configuration ensures that both TxOp1 and TxOp2 are invoked under the same client session, allowing them to run under the same transaction context.

    Rate this question:

  • 46. 

    You are creating a Window Commnunication Foundation (WCF) service application. The application needs to service many clients and requests simultaneously. The application also needs to ensure subsequent individual client requests provide a stateful conversation. You need to configure the service to support these requirements. Which attribute should you add to the class that is implementing the service?

    • A.

      [ServiceBehavior(lnstanceContextMode = lnstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]

    • B.

      [ServiceBehavior(lnstanceContextMode = lnstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Reentrant)]

    • C.

      [ServiceBehavior(InstanceContextMode = lnstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]

    • D.

      [ServiceBehavior(lnstanceContextMode = lnstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]

    Correct Answer
    C. [ServiceBehavior(InstanceContextMode = lnstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
    Explanation
    The correct answer is [ServiceBehavior(InstanceContextMode = lnstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]. This attribute configuration ensures that each client request will have its own session, allowing for stateful conversations. Additionally, the ConcurrencyMode is set to Multiple, which means that multiple client requests can be processed simultaneously.

    Rate this question:

  • 47. 

    You are integrating a Windows Communication Foundation (WCF) service within an enterprise-wide Service Oriented Architecture (SOA). Your service has the following service contract: [ServiceContract] public class CreditCardConfirmationService {     [OperationContract]     boolean ConfirmCreditCard(string ccNumber);         double OrderAmount(int orderNumber); } You need to allow the code in the ConfirmCreditCard method to participate automatically in existing transactions. If there is no existing transaction, a new transaction must be created automatically. What should you do?

    • A.

      Inside the ConfirmCreditCard method, surround the code that must participate in the transaction with a using(new TransactionScope()) block.

    • B.

      Inside the ConfirmCreditCard method, surround the code that must participate in the transaction with a using(new CommittableTransaction()) block.

    • C.

      Add an [OperationBehavior(TransactionScopeRequired=true)] attribute to the ConfirmCreditCard method.

    • D.

      Add an [OperationBehavior(TransactionAutoComplete=true)] attribute to the ConfirmCreditCard method.

    Correct Answer
    C. Add an [OperationBehavior(TransactionScopeRequired=true)] attribute to the ConfirmCreditCard method.
    Explanation
    Adding the [OperationBehavior(TransactionScopeRequired=true)] attribute to the ConfirmCreditCard method will allow the code to participate automatically in existing transactions. If there is no existing transaction, a new transaction will be created automatically. This attribute ensures that the method is executed within a transaction scope, providing transactional support for the method.

    Rate this question:

  • 48. 

    Your Windows Communication Foundation (WCF) client application uses HTTP to communicate with the service. You need to enable message logging and include all security information such as tokens and nonces in logged messages. What should you do?

    • A.

      In the application configuration file, add the IogKnownPii attribute to the message logging diagnostics source and set the value of the attribute to true. Generate the ContosoService class using the Add Service Reference wizard. Add a reference to System.ServiceModel.Routing.dll. Add the following code segment: ContosoService client = new ContosoService(); SoapProcessingBehavior behavior = new SoapProcessingBehavior(); behavior.ProcessMessages = true; client.Endpoint.Behaviors.Add(behavior);

    • B.

      In the application configuration file, add the following XML segment to the system.serviceModel configuration section group.

    • C.

      In the machine configuration file, add the following XML segment to the system.serviceModel configuration section. Generate the ContosoService class using the Add Service Reference wizard. Add the following code segment. ContosoService client = new ContosoService(); client.Endpoint.Behaviors.Add(new CallbackDebugBehavior(true));

    • D.

      In the machine configuration file, add the following XML segment to the system.serviceModel configuration section. In the application configuration file, add the IogKnownPii attribute to the message logging diagnostics source and set the value of the attribute to true. In the application configuration file, add the following XML segment to the system.serviceModel configuration section group.

    Correct Answer
    D. In the machine configuration file, add the following XML segment to the system.serviceModel configuration section. In the application configuration file, add the IogKnownPii attribute to the message logging diagnostics source and set the value of the attribute to true. In the application configuration file, add the following XML segment to the system.serviceModel configuration section group.
    Explanation
    To enable message logging and include all security information such as tokens and nonces in logged messages, you need to add the XML segment mentioned in the machine configuration file to the system.serviceModel configuration section. This will configure the WCF client application to log the messages and include the necessary security information. Additionally, there is no need to generate the ContosoService class using the Add Service Reference wizard or add the SoapProcessingBehavior code segment. The IogKnownPii attribute and XML segment in the application configuration file are not relevant for this requirement.

    Rate this question:

  • 49. 

    A Windows Communication Foundation (WCF) service has the following contract. [ServiceContract(Namespace="http://contoso.com")] public interface IShipping {     [OperationContract]     string DoWork(int id); } This is one of several service contracts hosted by your application. All endpoints use SOAP 1.2 bindings with WS-Addressing 1.0. The System.ServiceModel.MessageLogging trace source in the system.diagnostics configuration section is configured with one listener. You need to make sure that only the messages that are returned from the DoWork operation are logged. Which XML segment should you add to the system.serviceModel/diagnostics/messageLogging/filters configuration element?

    • A.

      /addr:Action[text()='http://contoso.com/lShipping/DoWorkResponse']

    • B.

      /soap:Action[text()='http://contoso.com/lShipping/DoWorkResponse']

    • C.

      /addr:Action[text()=`http://contoso.com/lShipping/DoWork']

    • D.

      /soap:Action[text()=`http://contoso.com/lShipping/DoWork']

    Correct Answer
    A. /addr:Action[text()='http://contoso.com/lShipping/DoWorkResponse']
    Explanation
    The correct XML segment to add to the system.serviceModel/diagnostics/messageLogging/filters configuration element is /addr:Action[text()='http://contoso.com/lShipping/DoWorkResponse']. This segment specifies that only messages with the action value of 'http://contoso.com/lShipping/DoWorkResponse' should be logged.

    Rate this question:

  • 50. 

    You are implementing a Windows Communication Foundation (WCF) service contract named lContosoService in a class named ContosoService. The service occasionally fails due to an exception being thrown at the service. You need to send the stack trace of any unhandled exceptions to clients as a fault message. What should you do?

    • A.

      In the application configuration file on the client, add the following XML segment to the system.serviceModel/behaviors configuration section group. Associate the debug behavior with any endpoints that need to return exception details.

    • B.

      In the application configuration file on the service and all the clients, add the following XML segment to the system.diagnostics/sources configuration section group.

    • C.

      Apply the following attribute to the ContosoService class. [ServiceBehavior(IncludeExceptionDetailInFaults = true)]

    • D.

      For each OperationContract exposed by lContosoService, apply the following attribute. [FaultContract(typeof(Exception))]

    Correct Answer
    C. Apply the following attribute to the ContosoService class. [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    Explanation
    By applying the [ServiceBehavior(IncludeExceptionDetailInFaults = true)] attribute to the ContosoService class, any unhandled exceptions thrown by the service will be sent as a fault message to the clients. This attribute allows the service to include exception details in the fault message, including the stack trace. This ensures that clients receive information about the exceptions that occurred on the server, helping them to diagnose and handle any errors effectively.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 27, 2012
    Quiz Created by
    Akshansh

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.