Whichcode segment should you insert at line 03?

You are creating a Windows Communication Foundation (WCF) service by using Microsoft .NET Framework 3.5.
You add the following code segment to the service.

public interface ICalulatorservice
{
[OperationContract]
[FaultContract(typeOf(ArithmeticException))]
double Divide(double number1, double number2);
[OperationContract]
void DisposeCalculator();
}
[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
public class Calculatorservice : ICalulatorservice
{
public double Divide(double number1, double number2)
{
if (number2 == 0) throw new DivideByZeroException();
return (number1 / number2);
}
public void DisposeCalculato()
{
// release resources.
}
}

You add the following code segment to the client application.

01 public double PerformCalculations (double num1, double num2)
02 {
03
04 }

You need to ensure that the DisposeCalculator operation is always called. Which
code segment should you insert at line 03?

You are creating a Windows Communication Foundation (WCF) service by using Microsoft .NET Framework 3.5.
You add the following code segment to the service.

public interface ICalulatorservice
{
[OperationContract]
[FaultContract(typeOf(ArithmeticException))]
double Divide(double number1, double number2);
[OperationContract]
void DisposeCalculator();
}
[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
public class Calculatorservice : ICalulatorservice
{
public double Divide(double number1, double number2)
{
if (number2 == 0) throw new DivideByZeroException();
return (number1 / number2);
}
public void DisposeCalculato()
{
// release resources.
}
}

You add the following code segment to the client application.

01 public double PerformCalculations (double num1, double num2)
02 {
03
04 }

You need to ensure that the DisposeCalculator operation is always called. Which
code segment should you insert at line 03?

A.
CalculatorClient proxy=new CalculatorClient();
int result=-1;
try
{
result=proxy.Divide(number1, numher2);
}
catch (DivideByZeroException dzEx)
{}
proxy.DisposeCalculator();
return result;

B.
CalculatorClient proxy=new CalculatorClient();
int result=-1;
try
{
result=proxy.Divide(number1, numher2);
}
catch (DivideByZeroException dzEx)
{
proxy.Close();
proxy=new CalculatorClient();
}
proxy.DisposeCalculator();
return result;

C.
CalculatorClient proxy=new CalculatorClient();
int result=-1;
try
{
result = proxy.Divide(number1, numher2);
}
catch (FaultException dzEx)
{}
proxy.DisposeCalculator();
return result;

D.
CalculatorClient proxy=new CalculatorClient();
int result=-1;
try
{
result=proxy.Divide(number1, number2);
}
catch (FaultException dzEx)
{
proxy.Close();
proxy=new CalculatorClient();
}
proxy.DisposeCalculator();
return result;



Leave a Reply 0

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