THURSDAY, AUGUST 07, 2008




MY ACCOUNT LOGIN

LOGIN NAME:

PASSWORD:

REGISTER TODAY!
FORGOT YOUR PASSWORD?
TRY ALL WEB SERVICES
FREE FOR 30 DAYS!

WEB SERVICES

XWEBEMAILVALIDATION [tool]

XWEB1003 [real estate]

XWEBACHDIRECTORY [financial]

XWEBCHECKOUT [ecommerce]

XWEBTD [ecommerce]

XWEBNEWS [content mgmt.]


ANNOUNCEMENTS


NEW IMPLEMENTATION GUIDE AVAILABLE: "XWEBFAQS CLIENT 2.0”

XWEBFAQS VERSION 2 LAUNCHED

NEW IMPLEMENTATION GUIDE AVAILABLE: "HOW-TO DISPLAY GROUPS OF FREQUENTLY ASKED QUESTIONS"

XWEBFAQS WEB SERVICE NOW FEATURES SSL SECURITY

NEW IMPLEMENTATION GUIDE AVAILABLE: "HOW-TO DISPLAY A LIST OF ALL FREQUENTLY ASKED QUESTIONS"



Web Services, SOA Solutions, SOA Services - XWebServices.com


HOME

WEB SERVICES

SOA SOLUTIONS

SOA SERVICES

ABOUT US





XWEBFAQs


Documentation


FAQs


Implementation Guides


Forum


Pricing






SEARCH









HOME  ::  WEB SERVICES  ::  XWEBFAQs  ::  IMPLEMENTATION GUIDES

:: Web Services :: XWebFAQs :: Implementation Guides ::

How-To Display Groups Of Frequently Asked Questions

First and foremost, before you write any code, you must first implement a numbering system that you must use when entering Frequently Asked Questions (FAQs). Let's presume that a website lists both products and services and therefore, needs to display a group of FAQs for products and another for services. For this implementation guide, let's presume that we began numbering the product related FAQs at 10,000 and the services FAQs at 20,000 - a big enough cushion for never overlapping the 2 groups.

Now for the code. The procedures in this implementation guide require that you have some knowledge of XML, XPATH and ASP.NET web development with the Microsoft Visual Basic.NET development tool.

The steps in this "how-to" implementation guide are:

To download the source code for this "how-to" implementation guide, as well as for additional hints and tips, please read our Final Notes.

Add a "Web Reference" to the XWebFAQs Web Service

  • In your web project, add a Web Reference to the XWebFAQs web service. Here are 2 ways you can accomplish this:

    • Browse the Solution Explorer, right click on References and select Add Web Reference... from the drop down menu.
    • From the File Menu, select Project - Add Web Reference....
  • The Add Web Reference pop-up window will open. In the URL textbox, enter the following URI:

    http://ws.xwebservices.com/XWebFAQs/XWebFAQs.asmx?wsdl

  • Hit the Enter key or click the Go button located to the right of the URL textbox.
  • Change the Web reference name to XWebFAQs for easier reference.
  • Click the Add Reference button to complete this step.

Add a "Web Form" to the Web Application

  • In your web project, add a Web Form. This Web Form will display all the Frequently Asked Question records you previously entered in your account. Here are 2 ways you can accomplish this:

    • Browse the Solution Explorer, right click the name of your project, and select Add - Add Web Form....
    • From the File Menu, select Project - Add Web Form....
  • Change the Name textbox in the Add New Item pop-up provided to faq_groups.aspx.

Write code in the "Codebehind" of the web form to retrieve all Frequently Asked Questions by consuming the XWebFAQs Web Service

Based on the documentation for the XWebFAQs web service, in order to successfully consume the web service, we will need to authenticate first using SOAP Headers. Here's how:

  • Open the "Codebehind" of the faq_groups.aspx web form we added to the web project in the previous step.
  • Since the web service requires SOAP Headers for authentication purposes, we must first create a new instance of the class representing the SOAP Header and then populate the SOAP Header values:

    ' handle authentication
    Dim objAuth As New XWebFAQs.AuthHeader
    objAuth.LoginName = "<my_login_name>"
    objAuth.Password = "<my_password>"

    NOTE***: Instead of hard-coding the LoginName and Password values, you may want to dynamically read them from the web.config file (LOGIN_NAME and PASSWORD must be added to the <AppSettings> section of the web.config file):

    objAuth.LoginName = System.Configuration.ConfigurationSettings.AppSettings("LOGIN_NAME")
    objAuth.Password = System.Configuration.ConfigurationSettings.AppSettings("PASSWORD")

  • Next, we need to create a new instance of the proxy class and assign the SOAP Header object to the member variable of the proxy class representing the SOAP Header:

    'create the XWebFAQs web service proxy
    Dim objFAQs As New XWebFAQs.XWebFAQs
    objFAQs.AuthHeaderValue = objAuth

  • We are now ready to call the method on the proxy class that communicates with the Web Service method and returns the Frequently Asked Question records we want displayed on the web page:

    'store the result in a variable
    Dim strFAQsXML As String = objFAQs.LoadFAQs()

Implement Two Repeaters to Display the Groups of Frequently Asked Questions

In the Codebehind, we need to declare 2 Repeaters. Next, we load the XML string returned by the SOAP method in an XMLDocument and using XPATH, create 2 XMLNodeLists that we then bind to both Repeaters' DataSource. Here's how:

  • Declare the Repeaters in the Codebehind:

    Protected rptProductFAQs, rptServicesFAQs As System.Web.UI.WebControls.Repeater

  • Load the XML string from the previous step into an XMLDocument:

    'load an XML DOM with the xml string returned by the SOAP method
    Dim objDOM As New System.Xml.XmlDocument
    objDOM.LoadXml(strFAQsXML)

  • Use XPATH to filter the products and services FAQs. Bind the XPATH generated XMLNodeLists to the Repeaters' DataSource and call the DataBind method:

    rptProductFAQs.DataSource = objDOM.DocumentElement.SelectNodes("//FAQ[@FAQ_ID >= 10000 and @FAQ_ID < 20000]")
    rptProductFAQs.DataBind()

    rptServicesFAQs.DataSource = objDOM.DocumentElement.SelectNodes("//FAQ[@FAQ_ID >= 20000 and @FAQ_ID < 30000]")
    rptServicesFAQs.DataBind()

In the HTML Editor, to keep things simple, each FAQ record will be displayed in a paragraph, with the question in bold, and the date the FAQ record was created in italics. Here are the necessary steps:

  • Add the Repeaters inside the body of your HTML page:

    <asp:Repeater ID="rptProductFAQs" Runat="server">
       <ItemTemplate>
       </ItemTemplate>
    </asp:Repeater>

    <asp:Repeater ID="rptServicesFAQs" Runat="server">
       <ItemTemplate>
       </ItemTemplate>
    </asp:Repeater>

  • Inside each Repeater's ItemTemplate, first we display the Question of the FAQ record. Since the Repeater is looping through XML Nodes (<FAQ>), we need to first bind to the <Question> element, then get its value:

    <b>
    <%# Container.DataItem.SelectSingleNode("Question").InnerText %>
    </b>

  • Next, we display each Answer of the FAQ record. Again, since the Repeater is looping through XML Nodes (<FAQ>), we need to bind to the <Answer> element, then get its value:

    <%# Container.DataItem.SelectSingleNode("Answer").InnerText %>

  • Finally, we display the FAQ record's created date. Since Date_Created is an attribute, we must handle it slightly different:

    <%# Container.DataItem.Attributes.ItemOf("Date_Created").Value %>

Final Notes

The source code for this "how-to" implementation guide can be downloaded by clicking the link below (zip file, contains the source code for all "how-to" implementation guides for the XWebFAQs Web Service)

XWebFAQsClient.zip

It's always good practice to implement a Try...Catch... error handling technique to handle some or all possible errors that may occur while the code is executing. We strongly recommend that you implement such a technique.



HOME
WEB SERVICES
SOA SOLUTIONS
SOA SERVICES
MY ACCOUNT
ABOUT US