Web Developer Framework 4.0 Sample Questions – 12

Question: You are implementing a WCF service library. You add a new code file that contains the following code segment. namespace ContosoWCF {[ServiceContract]public interface IRateService{[OperationContract]decimal GetCurrentRate();} public partial class RateService : IRateService{public decimal GetCurrentRate(){decimal currentRate = GetRateFromDatabase();return currentRate;}} } You build the service library and deploy its assembly to an IIS application. You need to ensure that the GetCurrentRate method can be called from JavaScript. What should you do?

  1. Add a file named Service.svc to the IIS application. Add the following code segment to the file. <%@ ServiceHost Service=”ContosoWCF.IRateService”Factory=”System.ServiceModel.Activation.WebScriptServiceHostFactory” %>
  2. Add a file named Service.svc to the IIS application. Add the following code segment to the file. <%@ ServiceHost Service=”ContosoWCF.RateService”Factory=”System.ServiceModel.Activation.WebScriptServiceHostFactory” %>
  3. Apply the ScriptService attribute to the RateService class. Rebuild the WCF service library, and redeploy the assembly to the IIS application.
  4. Apply the WebGet attribute to the GetCurrentRate interface method. Rebuild the WCF service library, and redeploy the assembly to the IIS application.

Correct Answer: 2


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


Question: You are implementing an ASP.NET Dynamic Data Web site. The Web site includes a data context that enables automatic scaffolding for all tables in the data model. The Global.asax.cs file contains the following code segment. public static void RegisterRoutes(RouteCollection routes) { {routes.Add(new DynamicDataRoute(“{table}/ListDetails.aspx”){Action = PageAction.List,ViewName = “ListDetails”,Model = DefaultModel});routes.Add(new DynamicDataRoute(“{table}/ListDetails.aspx”){Action = PageAction.Details,ViewName = “ListDetails”,Model = DefaultModel}); } You need to display the items in a table named Products by using a custom layout. What should you do?

  1. Add a new Web page named Products.aspx to the Dynamic DataPageTemplates folder of the Web site.
  2. Add a new folder named Products to the Dynamic DataCustomPages folder of the Web site. Add a new Web page named ListDetails.aspx to the Products folder.
  3. Add a new Web user control named Products.ascx to the Dynamic DataFilters folder of the Web site. In the code-behind file for the control, change the base class from UserControl to System.Web.DynamicData.QueryableFilterUserControl.
  4. Add a new Web user control named Products_ListDetails.ascx to the Dynamic DataEntityTemplates folder of the Web site. In the code-behind file for the control, change the base class from UserControl to System.Web.DynamicData.EntityTemplateUserControl.

Correct Answer: 2


Question: You create a new ASP.NET MVC 2 Web application. The following default routes are created in the Global.asax.cs file. (Line numbers are included for reference only.)
01 public static void RegisterRoutes(RouteCollection routes)
02 {
03 routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
04
05 routes.MapRoute( “Default”, “{controller}/{action}/{id}”, new { controller = “Home”, action = “Index”, id = “” } );
06 }
You implement a controller named HomeController that includes methods with the following signatures. public ActionResult About() public ActionResult Index() public ActionResult Details(int id) You need to ensure that the About action is invoked when the root URL of the site is accessed. What should you do?

  1. At line 04 in the Global.asax.cs file, add the following line of code. routes.MapRoute(“Default4Empty”, “/”, new {controller=”Home”, action=”About”} );
  2. At line 04 in the Global.asax.cs file, add the following line of code. routes.MapRoute(“Default”, “”, new { controller=”Home”, action=”About”} );
  3. Replace line 05 in the Global.asax.cs file with the following line of code. routes.MapRoute(“Default4Empty”,”{controller}/{action}/{id}”,new {controller=”Home”, action=”About”, id=””} );
  4. Replace line 05 in the Global.asax.cs file with the following line of code. routes.MapRoute(“Default”,”{controller}/{action}”,new { controller=”Home”, action =”About”} );

Correct Answer: 3


Question: You create a new ASP.NET MVC 2 Web application. The following default routes are created in the Global.asax.cs file. (Line numbers are included for reference only.)
01 public static void RegisterRoutes(RouteCollection routes)
02 {
03 routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
04
05 routes.MapRoute( “Default”, “{controller}/{action}/{id}”, new { controller = “Home”, action = “Index”, id = “” } );
06 }
You implement a controller named HomeController that includes methods with the following signatures. public ActionResult Index() public ActionResult Details ( int id ) public ActionResult DetailsByUsername(string username) You need to add a route to meet the following requirements. The details for a user must be displayed when a user name is entered as the path by invoking the DetailsByUsername action. User names can contain alphanumeric characters and underscores, and can be between 3 and 20 characters long. What should you do?

  1. Replace line 05 with the following code segment. routes.MapRoute(“Default”,”{controller}/{action}/{id}”,new { controller = “Home”, action = “DetailsByUsername”,id = “” });
  2. Replace line 05 with the following code segment. routes.MapRoute(“Default”,”{controller}/{action}/{username}”,new { controller = “Home”, action = “DetailsByUsername”,username = “” } ,new { username = @”w{3,20}” });
  3. At line 04, add the following code segment. routes.MapRoute(“Details by Username”,”{username}”,new { controller = “Home”, action = “DetailsByUsername” },new { username = @”w{3,20}” });
  4. At line 04, add the following code segment. routes.MapRoute(“Details by Username”,”{id}”,new { controller = “Home”, action = “DetailsByUsername” },new { id = @”w{3,20}” });

Correct Answer: 3

Tagged . Bookmark the permalink.

Leave a Reply