News:

SQL Table To C# Entity Model ConverterEntity Model (Class Properties) to SQL Table ConverterIf you encounter any trouble visiting our site, please contact us.

Mcq Answers for WCF

[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 serve.r You need to ensure that the client and server enlist in the same distributed transaction. What should you do?

  1. Add the following attributes to the SavePerson operation on IContosoService.

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

    [TransactionFlow(TransactionFlowOption.Mandatory)]
    [OperationBehavior(TransactionScope.Required = true)]
  3. 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)]
  4. 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)]
Answer: Answer is d

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?

  1. Insert the following attribute to OperationOne on lContosoService

    [TransactionFlow(TransactionFlowOption.Mandatory)]

    Insert the following attribute to OperationTwo on IContosoService

    [TransactionFlow(TransactionFlowOption.Mandatory)]
  2. Insert the following attribute to OperationOne on ContosoSeivice

    [OperationBehavior(TransactonScopeRequired=true, TransactionAutoComplete=false)]

    Insert the following attribute to OperationTwo on ContosoService.

    [OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=true)]
  3. Add the following XML segment to the application config file in the system serviceModel/bindings configuration section

    <netMsmqBinding>
    <binding name="contosoTx" durable="true" receiveContextEnabled="true" />
    </netMsmqBinding>

    Then use the NetMsmqBinding named contosoTx to listen for messages from the clients

  4. Add the following XML segment to the application config file in the systemserviceModel/bindings configuration section.

    <customBinding>
    <binding name="contosoTx">
    <transactionFlow />
    <binaryMessageEncoding />
    <msmqTransport durable="true" />
    </binding>
    </customBinding>

     Then use the CustommiBinding named contosoTx to listen fcw messages from the clierts.

Answer: Answer is b

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

  1. Change the service behavior to the following:

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

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
  3. Require the clients use threads, the Parallel Task Library, or other mechanism to issue service calls in parallel.

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

Answer: Answer is a, b

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 Add ServiceEndpoint(MyApplic ation lGreetingService", binding,`nettcpillocalhost 12345");
33 host OpenO:

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 Invalid Operation Exception 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.)

  1. Change the service contract definition in line 01 as follows.

    [ServiceContract(CallbackContract = typeof(INameService), SessionMode = SessionMode.Required)]
  2. Add the following attribute to the NameService class, before line 40.

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

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

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
Answer: Answer is c, d

[ServiceContract]
public class ContosoService
{
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
[OperationBehavior(TransactionScopeRequired=true,TransactionAutoComplete=false)]
void TxOp 1 (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?

  1. Update the service contract to read as follows.

    [ServiceContract(SessionMode=SessionMode.Required)]

    Add the following behavior to the service implementation

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
  2. 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)]
  3. Update the service contract to read as follows

    [ServiceContract(SessionMode=SessionMode.Allowed)]

    Add the followng behavior to the service implementation.

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
  4. Update the service contract to read as follows.

    [ServiceContract(SessionMode=SessionMode.Required)]

    Add the following behavior to the service implementation.

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
Answer: Answer is a

  1. [ServiceBehavior(lnstanceContextMode = lnstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
  2. [ServiceBehavior(lnstanceContextMode = lnstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode. Reentrant)]
  3. [ServiceBehavior(InstanceContextMode = lnstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
  4. [ServiceBehavior(lnstanceContextMode = lnstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
Answer: Answer is c

[ServiceContract]
public class CreditCardConfirmationService
{
[OperationContract]
Boolean ConfirmCreditCard(string cc Number);
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?

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

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

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

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

Answer: Answer is c

  1. 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 SoapProcessingBehavior0;
    behavior.ProcessMessages = true;
    client.Endpoint.Behaviors.Add(behavior);
  2. In the application configuration file, add the following XML segment to the system.serviceModel
    configuration section group.

    <diagnostics>
    <messageLogging LogMessagesAtTransportLevel="true"
    IogEntireMessage="true" />
    </diagnostics>
  3. In the machine configuration file, add the following XML segment to the system.serviceModel configuration section.

    <machineSettings enableLoggingKnownPii="true" />

    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));
  4. In the machine configuration file, add the following XML segment to the system.serviceModel configuration section.

    <machineSettings enableLoggingKnownPii="true" />

    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.

    <diagnostics>
    <messageLogging IogMessagesAtTransportLevel="true"/>
    </diagnostics>
Answer: Answer is d

[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?

  1. <add xmlns:addr="http://www.w3.org/2005/08/addressing">/addr:Action[text()='http://contoso.com/lShipping/ DoWorkResponse'] </add>
  2. <add xmlns:soap="http://www.w3.org/2003/05/soap-envelope">/soap:Action[text()='http://contoso.com/ lShipping/DoWorkResponse'] </add>
  3. <add xmlns:addr="http://www.w3.org/2005/08/addressing">/addr:Action[text()=`http://contoso.com/ lShipping/DoWork'] </add>
  4. <add xmlns: soap="http://www.w3.org/2003/05/soap-envelope">/soap:Action[text()=`http://contoso.com/ lShipping/DoWork'] </add>
Answer: Answer is a

  1. In the application configuration file on the client, add the following XML segment to the system. serviceModel/behaviors configuration section group.

    <endpointBehaviors>
    <behavior name="debug">
    <callbackDebug includeExceptionDetaillnFaults="true" />
    </behavior>
    </endpointBehaviors>

    Associate the debug behavior with any endpoints that need to return exception details.

  2. 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.

    <source name="System.ServiceModel" switchValue="Error" propagateActivty="true">
    <listeners>
    <add name="ServiceModelTraceListener" initializeData="appntracelog.
    svclog" type="System.Diagnostics.XmlWriterTraceListener" />
    </listeners>
    </source>
  3. Apply the following attribute to the ContosoService class.

    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
  4. For each OperationContract exposed by lContosoService, apply the following attribute.

    [FaultContract(typeof (Exception))]
Answer: Answer is c

Advertisement

BCS Preparation now even more easy. ReadBD is the place where you can find all kind of resources to be successful in BCS,Bank,Islami Bank exam and interview.

Looking for job. Try JobLoader- First ever job search engine in Bangladesh. All open bd jobs now a single mouse click away.

;