Setup for Coding CMS Web Services

The code sample in this chapter assumes that managing CMS assets (Channels, Postings, Templates, and so on) in a Web Property is understood and a good portion of the CMS PAPI is instinctive. Therefore, screen shots will only be shown for results and directives specific to this chapter. Please refer to other chapters in this book for CMS non Web Service details. Also, the simple error handling in the code throughout the code sample isn't meant to be the model for how to handle CMS exceptions; there is an application code block from Microsoft on how to do exception handling in .NET.

But before we can begin coding our Web Services, we need to do a little setup work. The BOTS Consulting Web site already has a channel structure and navigation that will accommodate what we will call Job Offerings. However, there are currently no general, summary, or detail templates or postings in that section of the BOTS Web site. So we will need to create them. Not to worry we'll keep it very simple.

NOTE: You don't need to have BOTS to create the code in this chapter. Just create or use channels, templates, and postings in your own site and change the names accordingly.


The steps we will go through to set up the BOTS Web site follow, first in brief and then in detail. It should take no more than about ten minutes to set up this environment.

  1. Set up the channel hierarchy (three easy channels).

  2. Set up the templates (two easy templates).

  3. Set up the template files and associate them with templates (two easy template files).

  4. Code the template files (relatively simple code is provided).

  5. Build the solution in VS.NET (three-finger salute but not Ctrl-Alt-Del).

  6. Create the postings (two easy postings).

  7. Install the Woodgrove sample data site (standard setup).

Set Up Channel Hierarchy

Using the Site Manager, ensure that we have, at a minimum, the channel hierarchy characterized in Table 33-2.

The jobs channel was called "growth" for Growth Opportunities in other parts of the book. But "jobs" for Job Offerings seemed a better descriptor for this code sample.

When you are done, it should look something like Figure 33-2.

Figure 33-2. Channel hierarchy for BOTS Job Offerings

graphics/33fig02.jpg

Table 33-2. Channel Hierarchy for BOTS Job Offerings

Channel

Parent Channel

Display Name

Default Page

Script URL

botsconsulting

Channels

BOTS Consulting

default

empty

careers

botsconsulting

Careers

default

empty

jobs

careers

Job Offerings

default

empty

Set Up Templates

Using the VS.NET MCMS Template Explorer, create the logical templates characterized in Table 33-3 (take the default values for all unspecified properties).

We added the two circled templates in Figure 33-3. Note that they are not yet associated with a template file, so the icon looks broken and there is a red check mark because they are still checked out.

Figure 33-3. Templates for BOTS Job Offerings

graphics/33fig03.gif

Set Up Template Files and Associate with Templates

Using the VS.NET Solution Explorer, create two physical template files in the Templates directory by copying the existing generic.aspx template file. Name them jobsummary.aspx and jobdetail.aspx, and save them to disk.

Table 33-3. Templates for BOTS Job Offerings

Template

Parent Template

Placeholder Definition Type

Placeholder Definition Name

JobSummary

BOTS Consulting

none

none

JobDetail

BOTS Consulting

HtmlPlaceholder

JobDescription Definition

NOTE: If you aren't using the BOTS code, the generic.aspx template file is just a stub that includes the header, footer, and left navigation used on the Web site. It also has the default console and a Web Form literal called BodyTitle in the content portion of the file. You could easily use a standard MCMS template file and add your own custom interface.


Using the VS.NET MCMS Template Explorer, associate the Template File property of the JobSummary template with the jobsummary.aspx file, and the TemplateFile property of the JobDetail template with the jobdetail.aspx file. The icon for each template should become unbroken, and if you check them, the red check mark should go away.

Back in the VS.NET Solution Explorer, edit the jobsummary.aspx file. Add a Web Form placeholder control named SummaryOfPostings just below the existing literal control in the content portion of the file. It should look something like Figure 33-4.

Figure 33-4. jobsummary.aspx

graphics/33fig04.gif

Edit the jobdetail.aspx file. Add an HtmlPlaceholderControl named JobDescription just below the existing literal in the content portion of the file. Also, choose JobDescription from the drop-down list for the PlaceholderToBind property. The result should look something like Figure 33-5.

Figure 33-5. jobdetail.aspx

graphics/33fig05.gif

Code the Template Files

Replace the Page_Load function in the jobsummary.aspx template file with the following code:

 private void Page_Load(object sender, System.EventArgs e) {   HtmlAnchor cmsPostingLink;   Literal cmsPostingDate;   CmsHttpContext cmsContext = CmsHttpContext.Current;   //Show the Posting DisplayName at the top of the content   BodyTitle.Text = "<b>" +     HttpUtility.HtmlEncode(       CmsHttpContext.Current.Posting.DisplayName) +     "</b>";   //Go through all the Postings in this Channel and Add details to   //the SummaryOfPostings Web Form Placeholder for each Posting   //sorted by StartDate   //Do not include the Posting named default   PostingCollection cmsChannelPostings =     cmsContext.Channel.Postings;   if (cmsChannelPostings != null)   {     cmsChannelPostings.SortByStartDate(false);     foreach (Posting cmsPosting in cmsChannelPostings)     {       if (cmsPosting.Name != "default")       {         //Format Hyperlink         cmsPostingLink = new HtmlAnchor();         cmsPostingLink.HRef = cmsPosting.Url;         cmsPostingLink.InnerText = cmsPosting.DisplayName;         cmsPostingLink.Attributes.Add("style","COLOR: gray");         SummaryOfPostings.Controls.Add(new LiteralControl("<p>"));         SummaryOfPostings.Controls.Add(cmsPostingLink);         SummaryOfPostings.Controls.Add(new LiteralControl(           "<br />Posted: " +           cmsPosting.StartDate.ToLongDateString()));         SummaryOfPostings.Controls.Add(new LiteralControl("</p>"));       }     }   } } 

The code basically shows a URL and StartDate for each posting in the channel except the default posting.

Ensure that the namespace and public class (initially called "generic" if copied from generic.aspx) near the top of the file are unique in your project. You may want to provide a more detailed comment.

 namespace botsconsulting.Templates {   /// <summary>   /// Summary description for jobsummary.   /// </summary>   public class jobsummary : System.Web.UI.Page 

This is the only custom code in this template file.

Replace the Page_Load function in the jobdetail.aspx template file with the following code:

 private void Page_Load(object sender, System.EventArgs e) {   //Show the Posting DisplayName at the top of the content   BodyTitle.Text = "<b>" +     HttpUtility.HtmlEncode(       CmsHttpContext.Current.Posting.DisplayName) +     "</b>"; } 

Ensure that the namespace and public class (initially called "generic" if copied from generic.aspx) near the top of the file are unique in your project. You may want to provide a more detailed comment.

 namespace botsconsulting.Templates {   /// <summary>   /// Summary description for jobdetail.   /// </summary>   public class jobdetail : System.Web.UI.Page 

This is the only custom code in this template file.

Build the Solution in VS.NET

This is an important step don't miss it. You can use Ctrl-Shift-B or choose Build Solution from the Build menu. Clearly, but hopefully unnecessary, you must deal with any errors before continuing.

Create Postings

Once the build is successful, browse to http://localhost/botsconsulting/careers/jobs in Internet Explorer.

NOTE: For the top navigation to work properly, you may want to create a posting named "default" in the careers channel. This posting can be based upon any template that allows navigation to the channel's children. However, it isn't required for this code sample to function. You could even create the default posting in the careers channel using the JobSummary template if you like. Give it a name of "default" and a display name something like "Check out our Job Offerings."


Follow these steps to create the default posting based upon the Job Summary template in the jobs channel:

  1. Click the Switch to Edit Site link on the right side of the channel Welcome page.

  2. Click the Create New Page link.

  3. Locate and click the BOTS Consulting link in the template gallery.

  4. Locate the JobSummary template and click its Select icon.

  5. There are no placeholders on this template, so simply click the Save New Page link.

  6. Type "default" into the Name text box.

  7. Type "Job Offerings" into the Display Name text box.

  8. Click OK to dismiss the dialog.

  9. Click the Approve link.

  10. Click the Switch to Live Site link.

Figure 33-6 shows what this default summary page will look like after the next steps are complete.

Figure 33-6. Summary posting in Internet Explorer

graphics/33fig06.jpg

Follow these steps to create the default posting based upon the Job Summary template in the jobs channel:

  1. Click the Switch to Edit Site link in the Web Author console of the default page in the jobs channel.

  2. Click the Create New Page link.

  3. Locate and click the BOTS Consulting link in the template gallery.

  4. Locate the JobDetail template and click its Select icon.

  5. Enter a job description like "SQL Server 2000 DBA must know DTS" into the placeholder.

  6. Type "BOTS.12345" into the Name text box.

  7. Type a job title like "SQL Server DBA" into the Display Name text box.

  8. Click OK to dismiss the dialog.

  9. Click the Approve link.

  10. Click the Switch to Live Site link.

Clicking the Job Offerings link on the left navigation should take you to the posting in the jobs channel named default, which should look something like Figure 33-6.

Clicking the SQL Server DBA link should take you back to the detail page for that posting, and it should look something like Figure 33-7.

Figure 33-7. Detail posting in Internet Explorer

graphics/33fig07.jpg

Install Woodgrove Sample Data Site

The Woodgrove Bank sample that comes with CMS will be used to syndicate postings to the BOTS Consulting Web site. So if you don't already have Woodgrove installed, you need to do that now. There are detailed instructions for installing the sample both in the CMS help file and on MSDN. As always, you have the option of using your own site and just changing the names as needed.

That is all the setup we need to do, so let's code up a Web Service!



Microsoft Content Management Server 2002. A Complete Guide
Microsoft Content Management Server 2002: A Complete Guide
ISBN: 0321194446
EAN: 2147483647
Year: 2003
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net