Which code segment should you replace at lines 02 and 03?

You are developing an application by using Silverlight 4 and Microsoft .NET Framework 4. The application contains the following XAML fragment.
<TextBlock x:Name=”QuoteOfTheDay” />
The application calls a Windows Communication Foundation (WCF) service named MyService that returns the quote of the day and assigns it to the QuoteOfTheDay TextBlock.
The application contains the following code segment. (Line numbers are included for reference only.)

01 var client = new MyService.MyServiceClient();
02 client.GetQuoteOfTheDayCompleted += (s, args) => QuoteOfTheDay.Text = args.Result;
03 client.GetQuoteOfTheDayAsync();

You need to handle errors that might occur as a result of the service call. You also need to provide a default value of “Unavailable” when an error occurs.
Which code segment should you replace at lines 02 and 03?

You are developing an application by using Silverlight 4 and Microsoft .NET Framework 4. The application contains the following XAML fragment.
<TextBlock x:Name=”QuoteOfTheDay” />
The application calls a Windows Communication Foundation (WCF) service named MyService that returns the quote of the day and assigns it to the QuoteOfTheDay TextBlock.
The application contains the following code segment. (Line numbers are included for reference only.)

01 var client = new MyService.MyServiceClient();
02 client.GetQuoteOfTheDayCompleted += (s, args) => QuoteOfTheDay.Text = args.Result;
03 client.GetQuoteOfTheDayAsync();

You need to handle errors that might occur as a result of the service call. You also need to provide a default value of “Unavailable” when an error occurs.
Which code segment should you replace at lines 02 and 03?

A.
QuoteOfTheDay.Text = “Unavailable”;
client.GetQuoteOfTheDayCompleted += (s, args) => QuoteOfTheDay.Text = args.Result;
client.GetQuoteOfTheDayAsync();

B.
client.GetQuoteOfTheDayCompleted += (s, args) =>
{
if (args.Result != null)
{
QuoteOfTheDay.Text = args.Result;
}
else
{
QuoteOfTheDay.Text = “Unavailable”;
}
};
client.GetQuoteOfTheDayAsync();

C.
client.GetQuoteOfTheDayCompleted += (s, args) => QuoteOfTheDay.Text =
args.Result;
try
{
client.GetQuoteOfTheDayAsync();
}
catch (Exception ex)
{
// TODO: handle exception
QuoteOfTheDay.Text = “Unavailable”;
}

D.
client.GetQuoteOfTheDayCompleted += (s, args) =>
{
if (args.Error == null)
{
QuoteOfTheDay.Text = args.Result;
}
else
{
// TODO: handle error
QuoteOfTheDay.Text = “Unavailable”;
}
};
client.GetQuoteOfTheDayAsync();



Leave a Reply 0

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