Which code segment should you use?

A Windows Communication Foundation (WCF) service handles online order processing for your company.
You discover that many requests are being made with invalid account numbers.
You create a class named AccountNumberValidator that has a method named Validate.
Before the message is processed, you need to validate account numbers with AccountNumberValidator and reject messages with invalid account numbers.
You create a new class that implements the IParameterInspector interface. Which code segment should you use?

A Windows Communication Foundation (WCF) service handles online order processing for your company.
You discover that many requests are being made with invalid account numbers.
You create a class named AccountNumberValidator that has a method named Validate.
Before the message is processed, you need to validate account numbers with AccountNumberValidator and reject messages with invalid account numbers.
You create a new class that implements the IParameterInspector interface. Which code segment should you use?

A.
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
String accountNumber = GetAccountNumber(outputs);
var validator = newAccountNumberValidator();
if(validator.Validate(accountNumber))
{
throw new FaultException();
}
}
public object BeforeCall(string operationName, object[]inputs)
{
return null;
}

B.
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
return;
}
public object BeforeCall(string operationName, object[] inputs)
{
return null;
}

C.
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
String accountNumber = GetAccountNumber(outputs);
var validator = newAccountNumberValidator();
if( !validator.Validate(accountNumber))
{
return value = new FaultException();
}
}
public object BeforeCall(string operationName, object[]inputs)
{
return null;
}

D.
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
return;
}
public object BeforeCall(string operationName, object[]inputs)
{
string accountNumber = GetAccountNumber(inputs);
var validator = newAccountNumberValidator();
if (!validator.Validate(accountNumber))
{
return new FaultException();
}
}

Explanation:
http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aftercall(v=vs.110).aspx

I saw the variant B!!!

AfterCall:
Called after client calls are returned and before service responses are sent.

On outbound calls from a client, the inspector is invoked before the request contents are serialized and sent to the service.
The inspector is also called after the response has been deserialized but before the return values have been dispatched to the proxy method.
On inbound calls to a service, the inspector is invoked after parameters are deserialized but before they are dispatched to the service operation.

BeforeCall:
Called before client calls are sent and after service responses are returned.

On outbound calls from a client, the inspector is invoked before the request contents are serialized and sent to the service.
The inspector is also called after the response has been deserialized but before the return values have been dispatched to the proxy method.
On inbound calls to a service, the inspector is invoked after the request contents are deserialized and dispatched to the service operation
and before the response contents are serialized and sent to the client.



Leave a Reply 3

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


valenburm

valenburm

D is wrong. An exception is as follows: not all code paths return a value.
Correct answer is B, although BeforeCall method doesn’t contain all code.
Must be
public object BeforeCall(string operationName, object[] inputs)
{
string accountNumber = GetAccountNumber(inputs);
var validator = new AccountNumberValidator();
if (!validator.Validate(accountNumber))
{
throw new FaultException();
}
return null;
}

Gehan

Gehan

Answer Is B

X

X

There is no right answer according to valenburm.
You have to thrown exception inside BeforeCall method, not return it like D.