Web Developer Framework 4.0 Sample Questions – 26

Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. The application uses the following object query to load a product from the database. (Line numbers are included for reference only.)
01 using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities())
02 {
03 ObjectQuery<Product> productQuery = advWorksContext.Product.Where(“it.ProductID = 900”);
04
05 }
You need to log the command that the query executes against the data source.
Which code segment should you insert at line 04

  1. Trace.WriteLine(productQuery.ToString());
  2. Trace.WriteLine(productQuery.ToTraceString());
  3. Trace.WriteLine(productQuery.CommandText);
  4. Trace.WriteLine(((IQueryable)productQuery).Expression);

Correct Answer: 2


Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You write the following code segment that executes two commands against the database within a transaction. (Line numbers are included for reference only.)
01 using (SqlConnection connection = new SqlConnection(cnnStr)) {
02 connection.Open();
03 SqlTransaction sqlTran = connection.BeginTransaction();
04 SqlCommand command = connection.CreateCommand();
05 command.Transaction = sqlTran;
06 try {
07 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong size’)”;
08 command.ExecuteNonQuery();
09 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong color’)”;
10 command.ExecuteNonQuery();
11
12 }
You need to log error information if the transaction fails to commit or roll back.
Which code segment should you insert at line 11

  1. sqlTran.Commit();
    }
    catch (Exception ex)
    {
    sqlTran.Rollback();
    Trace.WriteLine(ex.Message);
    }
  2. sqlTran.Commit();
    }
    catch (Exception ex){
    Trace.WriteLine(ex.Message);
    try{
    sqlTran.Rollback();
    }
    catch (Exception exRollback){
    Trace.WriteLine(exRollback.Message);
    }
    }
  3. }
    catch (Exception ex){
    Trace.WriteLine(ex.Message);
    try{
    sqlTran.Rollback();
    }
    catch (Exception exRollback){
    Trace.WriteLine(exRollback.Message);
    }
    }
    finally{
    sqlTran.Commit();
    }
  4. }
    catch (Exception ex){
    sqlTran.Rollback();
    Trace.WriteLine(ex.Message);
    }
    finally{
    try{
    sqlTran.Commit();
    }
    catch (Exception exCommit){
    Trace.WriteLine(exCommit.Message);
    }
    }

Correct Answer: 2


Question: A WCF service code is implemented as follows. (Line numbers are included for reference only.)
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 {
24 }
25 }
You need to decrease the response time of the service. What are two possible 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 service.

Correct Answer: 1 & 2


Question: You are implementing an ASP.NET page. Client-side script requires data. Your application includes a class named Person with a Name property of type string. The code-behind file of the page includes the following code segment.
public string JsonValue;
List<Person> people = GetPeopleList();
JavaScriptSerializer json = new JavaScriptSerializer();

You need to use the JavaScriptSerializer class to serialize only the value of the Name property of each item in the people list.
Which code segment should you use

  1. JsonValue = json.Serialize(people.Select(p => p.Name));
    var names = from person in people select person;
  2. JsonValue = "{" + json.Serialize(names) + "}";
  3. JsonValue = json.Serialize(people.SelectMany( p => p.Name.AsEnumerable()));
    var names = from person in people select person;
  4. JsonValue = json.Serialize(names);

Correct Answer: 1


Question: You are implementing an ASP.NET Web site. The site contains the following class.
public class Address
{
public int AddressType;
public string Line1;
public string Line2;
public string City;
public string ZipPostalCode;
}

The Web site interacts with an external data service that requires Address instances to be given in the following XML format.
<Address AddressType="2">
<Line1>250 Race Court</Line1>
<City>Chicago</City>
<PostalCode>60603</PostalCode>
</Address>

You need to ensure that Address instances that are serialized by the XmlSerializer class meet the XML format requirements of the external data service. Which two actions should you perform (Each correct answer presents part of the solution. Choose two.)

  1. Add the following attribute to the AddressType field.
    [XmlAttribute]
  2. Add the following attribute to the Line2 field.
    [XmlElement(IsNullable=true)]
  3. Add the following attribute to the ZipPostalCode field.
    [XmlAttribute(“PostalCode”)]
  4. Add the following attribute to the ZipPostalCode field.
    [XmlElement(“PostalCode”)]

Correct Answer: 1 & 4

Tagged . Bookmark the permalink.

Leave a Reply