
|

|
:: Web Services :: XWebCheckOut :: Implementation Guides ::
|
Build Your Own XML/SOAP Web Service Based Shopping Cart
Handle Billing 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
|
 |
Write code in the "Codebehind" of the web form to retrieve the Billing 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 Billing 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
Billing 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:
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:
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:
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 Billing 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 Billing information and the button that when clicked, will store
the Billing 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 Billing information already exists, then we
populate the textboxes:
Dim billingNode As System.Xml.XmlNode
billingNode = orderDOM.DocumentElement.SelectSingleNode("Billing")
If Not billingNode Is Nothing Then
txtFirstName.Text = billingNode.SelectSingleNode("First_Name").InnerText
txtMiddleName.Text = billingNode.SelectSingleNode("Middle_Name").InnerText
txtLastName.Text = billingNode.SelectSingleNode("Last_Name").InnerText
txtAddress1.Text = billingNode.SelectSingleNode("Address_1").InnerText
txtAddress2.Text = billingNode.SelectSingleNode("Address_2").InnerText
txtCity.Text = billingNode.SelectSingleNode("City").InnerText
txtState.Text = billingNode.SelectSingleNode("State").InnerText
txtPostalCode.Text = billingNode.SelectSingleNode("Postal_Code").InnerText
txtCountry.Text = billingNode.SelectSingleNode("Country").InnerText
txtPhone.Text = billingNode.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 Credit Card Details"
Runat="server" />
</Form>
Finally, in the Code Behind, we handle the button's Click event and store the Billing information:
Dim orderDOM As New System.Xml.XmlDocument
orderDOM.AppendChild(orderDOM.CreateElement("Order"))
Dim oidAttribute As System.Xml.XmlAttribute =
orderDOM.CreateAttribute("Order_ID")
oidAttribute.InnerText = Request.Cookies("OID").Value
orderDOM.DocumentElement.Attributes.Append(oidAttribute)
Dim billingNode As System.Xml.XmlElement =
orderDOM.CreateElement("Billing")
Dim fnNode As System.Xml.XmlElement =
orderDOM.CreateElement("First_Name")
fnNode.InnerText = txtFirstName.Text
billingNode.AppendChild(fnNode)
Dim mnNode As System.Xml.XmlElement =
orderDOM.CreateElement("Middle_Name")
mnNode.InnerText = txtMiddleName.Text
billingNode.AppendChild(mnNode)
Dim lnNode As System.Xml.XmlElement =
orderDOM.CreateElement("Last_Name")
lnNode.InnerText = txtLastName.Text
billingNode.AppendChild(lnNode)
Dim address1Node As System.Xml.XmlElement =
orderDOM.CreateElement("Address_1")
address1Node.InnerText = txtAddress1.Text
billingNode.AppendChild(address1Node)
Dim address2Node As System.Xml.XmlElement =
orderDOM.CreateElement("Address_2")
address2Node.InnerText = txtAddress2.Text
billingNode.AppendChild(address2Node)
Dim cityNode As System.Xml.XmlElement =
orderDOM.CreateElement("City")
cityNode.InnerText = txtCity.Text
billingNode.AppendChild(cityNode)
Dim stateNode As System.Xml.XmlElement =
orderDOM.CreateElement("State")
stateNode.InnerText = txtState.Text
billingNode.AppendChild(stateNode)
Dim pcNode As System.Xml.XmlElement =
orderDOM.CreateElement("Postal_Code")
pcNode.InnerText = txtPostalCode.Text
billingNode.AppendChild(pcNode)
Dim countryNode As System.Xml.XmlElement =
orderDOM.CreateElement("Country")
countryNode.InnerText = txtCountry.Text
billingNode.AppendChild(countryNode)
Dim phoneNode As System.Xml.XmlElement =
orderDOM.CreateElement("Phone")
phoneNode.InnerText = txtPhone.Text
billingNode.AppendChild(phoneNode)
orderDOM.DocumentElement.AppendChild(billingNode)
Dim objAuth As New XWebCheckOut.AuthHeader
objAuth.LoginName =
System.Configuration.ConfigurationSettings.AppSettings("LOGIN_NAME")
objAuth.Password =
System.Configuration.ConfigurationSettings.AppSettings("PASSWORD")
Dim objOrder As New XWebCheckOut.XWebCheckOut
objOrder.AuthHeaderValue = objAuth
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
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.
|
|

|

|
|