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: "XWEBCHECKOUT CLIENT 2.0”

XWEBCHECKOUT VERSION 2 LAUNCHED

NEW IMPLEMENTATION GUIDE AVAILABLE: "BUILD YOUR OWN XML/SOAP WEB SERVICE BASED SHOPPING CART - HANDLE CREDIT CARD DETAILS”

NEW IMPLEMENTATION GUIDE AVAILABLE: "BUILD YOUR OWN XML/SOAP WEB SERVICE BASED SHOPPING CART - HANDLE BILLING INFORMATION”

NEW IMPLEMENTATION GUIDE AVAILABLE: "BUILD YOUR OWN XML/SOAP WEB SERVICE BASED SHOPPING CART - HANDLE SHIPPING INFORMATION”



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


HOME

WEB SERVICES

SOA SOLUTIONS

SOA SERVICES

ABOUT US





XWEBCHECKOUT


Documentation


FAQs


Implementation Guides


Forum


Pricing






SEARCH









HOME  ::  WEB SERVICES  ::  XWEBCHECKOUT  ::  IMPLEMENTATION GUIDES

:: Web Services :: XWebCheckOut :: Implementation Guides ::

Build Your Own XML/SOAP Web Service Based Shopping Cart
Handle Shipping Information

The procedures in this implementation guide require that you have some knowledge of XML 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 XWebCheckOut Web Service

  • In your web project, add a Web Reference to the XWebCheckOut 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:

    https://ws.xwebservices.com/XWebCheckOut/XWebCheckOut.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 XWebCheckOut 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 is the Web Form that will host the ASP.NET Form which will display and allow for edits to be made to the shipping information. 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 shipping.aspx.

Write code in the "Codebehind" of the web form to retrieve the Shipping information by consuming the XWebCheckOut Web Service

Before we begin talking about code, we must keep in mind that during checkout, a visitor may go back and forth between the checkout process steps. Therefore, we account for Shipping information already being provided every time the page loads.

In the first "how-to" implementation guide of our Build Your Own XML/SOAP Web Service Based Shopping Cart series, every order is assigned an Order ID and the Order ID is then stored in a cookie. Using the Order ID stored in the cookie, in the Page_Load subroutine of the web form, we retrieve the Shipping information by consuming the LoadOrder SOAP method of the XWebCheckOut Web Service:

  • 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 XWebCheckOut.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 XWebCheckOut web service proxy
    Dim objOrder As New XWebCheckOut.XWebCheckOut
    objOrder.AuthHeaderValue = objAuth

  • We are now ready to call the method on the proxy class that communicates with the Web Service SOAP Method and returns the Order record we requested. Since the method returns the Order record in the form of an XML string, we load an XML DOM with it:

    ' load the xml string into a DOM
    Dim orderDOM As New System.Xml.XmlDocument
    orderDOM.LoadXml(objOrder.LoadOrder(Request.Cookies("OID").Value))

Implement an ASP.NET Form that displays and allows for edits to be made to the Shipping information

In the Code Editor, we really don't need to declare a Form since there won't be anything that we will be doing with the actual form itself. Instead we need to declare the textboxes that will display the Shipping information and the button that when clicked, will store the Shipping information changes. Then, using the XML DOM, we populate the textbox values. Here's how:

  • Declare the textboxes in the Code Editor, using the Order XSD validation schema as a guide:

    Protected txtFirstName, txtMiddleName, txtLastName, txtAddress1, txtAddress2, txtCity, txtState, txtPostalCode, txtCountry, txtPhone As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnProceed As System.Web.UI.WebControls.Button

  • In the Page_Load subroutine of the web form, since the Order's data is already in an XML DOM, we first check to see if Shipping information already exists, then we populate the textboxes:

    ' handle the Shipping element
    Dim shippingNode As System.Xml.XmlNode
    shippingNode = orderDOM.DocumentElement.SelectSingleNode("Shipping")

    ' check if Shipping information already exists
    If Not shippingNode Is Nothing Then
       txtFirstName.Text =
          shippingNode.SelectSingleNode("First_Name").InnerText
       txtMiddleName.Text =
          shippingNode.SelectSingleNode("Middle_Name").InnerText
       txtLastName.Text =
          shippingNode.SelectSingleNode("Last_Name").InnerText
       txtAddress1.Text =
          shippingNode.SelectSingleNode("Address_1").InnerText
       txtAddress2.Text =
          shippingNode.SelectSingleNode("Address_2").InnerText
       txtCity.Text =
          shippingNode.SelectSingleNode("City").InnerText
       txtState.Text =
          shippingNode.SelectSingleNode("State").InnerText
       txtPostalCode.Text =
          shippingNode.SelectSingleNode("Postal_Code").InnerText
       txtCountry.Text =
          shippingNode.SelectSingleNode("Country").InnerText
       txtPhone.Text =
          shippingNode.SelectSingleNode("Phone").InnerText
    End If

In the HTML Editor, we define the ASP.NET form, the ASP.NET textboxes, and an ASP.NET button. Here is the code:

<Form Runat="server">
   <asp:TextBox ID="txtFirstName" MaxLength="50" Runat="server" />
   <asp:TextBox ID="txtMiddleName" MaxLength="50" Runat="server" />
   <asp:TextBox ID="txtLastName" MaxLength="50" Runat="server" />
   <asp:TextBox ID="txtAddress1" MaxLength="255" Runat="server" />
   <asp:TextBox ID="txtAddress2" MaxLength="255" Runat="server" />
   <asp:TextBox ID="txtCity" MaxLength="50" Runat="server" />
   <asp:TextBox ID="txtState" MaxLength="50" Runat="server" />
   <asp:TextBox ID="txtPostalCode" MaxLength="20" Runat="server" />
   <asp:TextBox ID="txtCountry" MaxLength="50" Runat="server" />
   <asp:TextBox ID="txtPhone" MaxLength="20" Runat="server" />
   <asp:Button ID="btnProceed" Text="Proceed To Billing" Runat="server" />
</Form>

Finally, in the Code Behind, we handle the button's Click event and store the Shipping information:

' create an order DOM
Dim orderDOM As New System.Xml.XmlDocument
orderDOM.AppendChild(orderDOM.CreateElement("Order"))

'add the order id
Dim oidAttribute As System.Xml.XmlAttribute =
   orderDOM.CreateAttribute("Order_ID")
oidAttribute.InnerText = Request.Cookies("OID").Value
orderDOM.DocumentElement.Attributes.Append(oidAttribute)

' add the Shipping node
Dim shippingNode As System.Xml.XmlElement =
   orderDOM.CreateElement("Shipping")

' add the children
Dim fnNode As System.Xml.XmlElement =
   orderDOM.CreateElement("First_Name")
fnNode.InnerText = txtFirstName.Text
shippingNode.AppendChild(fnNode)

Dim mnNode As System.Xml.XmlElement =
   orderDOM.CreateElement("Middle_Name")
mnNode.InnerText = txtMiddleName.Text
shippingNode.AppendChild(mnNode)

Dim lnNode As System.Xml.XmlElement =
   orderDOM.CreateElement("Last_Name")
lnNode.InnerText = txtLastName.Text
shippingNode.AppendChild(lnNode)

Dim address1Node As System.Xml.XmlElement =
   orderDOM.CreateElement("Address_1")
address1Node.InnerText = txtAddress1.Text
shippingNode.AppendChild(address1Node)

Dim address2Node As System.Xml.XmlElement =
   orderDOM.CreateElement("Address_2")
address2Node.InnerText = txtAddress2.Text
shippingNode.AppendChild(address2Node)

Dim cityNode As System.Xml.XmlElement =
   orderDOM.CreateElement("City")
cityNode.InnerText = txtCity.Text
shippingNode.AppendChild(cityNode)

Dim stateNode As System.Xml.XmlElement =
   orderDOM.CreateElement("State")
stateNode.InnerText = txtState.Text
shippingNode.AppendChild(stateNode)

Dim pcNode As System.Xml.XmlElement =
   orderDOM.CreateElement("Postal_Code")
pcNode.InnerText = txtPostalCode.Text
shippingNode.AppendChild(pcNode)

Dim countryNode As System.Xml.XmlElement =
   orderDOM.CreateElement("Country")
countryNode.InnerText = txtCountry.Text
shippingNode.AppendChild(countryNode)

Dim phoneNode As System.Xml.XmlElement =
   orderDOM.CreateElement("Phone")
phoneNode.InnerText = txtPhone.Text
shippingNode.AppendChild(phoneNode)

' append the Shipping Node
orderDOM.DocumentElement.AppendChild(shippingNode)

' store the Shipping information
' handle authentication
Dim objAuth As New XWebCheckOut.AuthHeader
objAuth.LoginName =
   System.Configuration.ConfigurationSettings.AppSettings("LOGIN_NAME")
objAuth.Password =
   System.Configuration.ConfigurationSettings.AppSettings("PASSWORD")

' create the XWebCheckOut web service proxy
Dim objOrder As New XWebCheckOut.XWebCheckOut
objOrder.AuthHeaderValue = objAuth

' call the ProcessOrder SOAP method
Dim strResult As String =
   objOrder.ProcessOrder(orderDOM.DocumentElement.OuterXml)
If strResult <> "" Then Throw New Exception(strResult)

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 XWebCheckOut Web Service)

XWebCheckOutClient.zip

We did not cover manipulating the basket's total amount by adding a shipping price to it since the same steps as those outlined in the first "how-to" implementation guide of our Build Your Own XML/SOAP Web Service Based Shopping Cart series are to be followed.

The XWebCheckOut Web Service can also store Shipping special requests and commments. Simply add a <Comments> node to the Order DOM and then store each comment or special request as its own <Comment> node.

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