You are writing a .NET Framework remoting client application that must call two remoting servers.
The first server hosts an assembly that contains the following delegate and class definition.
public delegate bool IsValidDelegate(string number, Int16 code);
public class CreditCardValidator : MarshalByRefObject
{
public bool IsValid (string number, Int16 code)
{
//some data access calls that are slow under heavy load …
}
}
The second server hosts an assembly that contains the following delegate and class definition.
public delegate float GetCustomerDiscountDelegate( int customerId);
public class PreferredCustomer
{
public float GetCustomerDiscount(int customerId)
{
//some data access calls that are slow under heavy load …
}
}
You configure the remoting client application to call both server classes remotely.
The amount of time it takes to return these calls varies, and long response times occur during heavy load times.
The processing requires the result from both calls to be returned.
You need to ensure that calls to both remoting servers can run at the same time.
What should you do?
A.
Write the following code segment in the client application.
PreferredCustomer pc = new PreferredCustomer();
CreditCardValidator val = new CreditCardValidator();
double discount =
pc.GetCustomerDiscount(1001);
bool isValid = val.IsValid(“4111-2222-3333-4444”, 123);
B.
Write the following code segment in the client application.
PreferredCustomer pc = new PreferredCustomer();
GetCustomerDiscountDelegate del1 = new GetCustomerDiscountDelegate(pc.GetCustomerDiscount);
CreditCardValidator val = new CreditCardValidator();
IsValidDelegate del2 = new IsValidDelegate(val.IsValid);
double discount = del1.Invoke(1001);
bool isValid = del2.Invoke(“4111-2222-3333-4444”, 123);
C.
Write the following code segment in the client application.
PreferredCustomer pc = new PreferredCustomer();
GetCustomerDiscountDelegate del1 = new
GetCustomerDiscountDelegate(pc.GetCustomerDiscount);
IAsyncResult res1 = del1.BeginInvoke(1001, null, null);
CreditCardValidator val = new CreditCardValidator();
IsValidDelegate del2 = new IsValidDelegate(val.IsValid);
IAsyncResult res2 = del2.BeginInvoke(“4111-2222-3333-4444” , 123, null, null);
WaitHandle[] waitHandles = new WaitHandle[] {res1.AsyncWaitHandle, res2.AsyncWaitHandle};
ManualResetEvent.WaitAll(waitHandles);
double discount = del1.EndInvoke(res1);
bool isValid = del2.EndInvoke(res2);
D.
Write the following code segment in the client application.
PreferredCustomer pc = new PreferredCustomer();
GetCustomerDiscountDelegate del1 = new GetCustomerDiscountDelegate(pc.GetCustomerDiscount);
IAsyncResult res1 = del1.BeginInvoke(1001, null,
null);double discount = del1.EndInvoke(res1);
CreditCardValidator val = new CreditCardValidator();
IsValidDelegate del2 = new IsValidDelegate( val.IsValid);
IAsyncResult res2 = del2.BeginInvoke(“4111-2222-3333-4444”, 123, null, null);
bool isValid = del2.EndInvoke(res1);