View Single Post
  #1 (permalink)  
Old August 23rd, 2006, 10:19 AM
kbrown kbrown is offline
Registered User
Join Date: Aug 2006
Location: Chippewa Falls, WI, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 15, POSTing a SOAP message ;example on 579

I was hoping I would find some postings on the example beginning on page 579, POSTing a SOAP message. Any information to explain debug would be much appreciated. I really want to successfully run this exercise.

I have created the files the examples lists (addtocart.asp and soapclient.asp) However when I "Add to Cart", I get the following error message:
Error -1072896659

The error occurs in this section, specifically at xhHTTP.send(xdDoc)...
xdDoc = new ActiveXObject("MSXML.DOMDocument");
xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");"POST","http://localhost/soap/submitOrder1.asp",false);

Perhaps this is a common newbie error? I've run out of ideas as to how to fix the error and I don't understand why the error is occurring.

What I am really unclear in regard to this exercise, is how addtocart.asp even ties into this example. soapclient.html has a form that submits to a javascript function sendOrder(). That function as you see above attempts to post to submitOrder1.asp. soapclient.html doesn't reference addtocart.asp at all? And submitOrder1.asp doesn't exist - am I attempting to create it?

I'll post both source files below. If you've successfully created this example any input would be MUCH appreciated!

<title>GET Leads</title>
<script language="JavaScript">
function updateTotal() {
    var unitPrice = orderForm.unitPrice.value;
    var qty = orderForm.qty.value;
    xdDoc = new ActiveXObject("MSXML.DOMDocument");
    xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");
    //alert("http://localhost/soap/updateTotal2.asp?quantity="+qty+"&unitPrice="+unit Price)"GET","http://localhost/soap/updateTotal2.asp?quantity="+qty+"&unitPrice="+unit Price, false);
    var discount, extPrice;
    discount=xdDoc.selectSingleNode("//o:discount").text + "% off";
    document.getElementById("discount").innerHTML=disc ount;

function sendOrder() {
    var xdDoc, xhHTTP, sXML
    sXML="<env:Envelope xmlns:env="
    sXML=sXML + "''>"
    sXML=sXML + "<env:Body>"
    sXML=sXML + "<o:addToCart "+
    sXML=sXML + "<o:cartId>"+orderForm.cartId.value+"</o:cartId>";
    sXML=sXML + "<o:item itemId='"+orderForm.itemId.value+"'>";
    sXML=sXML + "<o:quantity>"+orderForm.qty.value+"</o:quanity>"
    sXML=sXML + "<o:extPrice>"+orderForm.extPrice.value+"</o:extPrice>";
    sXML=sXML + "</O:item>";
    sXML=sXML + "</o:addToCart>";
    sXML=sXML + "</env:Body>";
    sXML=sXML + "</env:Envelope>";

    xdDoc = new ActiveXObject("MSXML.DOMDocument");

    xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");"POST","http://localhost/soap/submitOrder1.asp",false);
    xdDoc = xhHTTP.responseXML;
    var responseName;
    responseName = xdDoc.selectSingleNode("//env:Body").firstChild.nodeName;

    if (responseName == "env:Fault") {
        var reason, message
        reason = xdDoc.selectSingleNode("//env:Reason/env:Text").firstChild.nodeValue;
    } else {
        var orderNumber, status, total;
        cartId = xdDoc.selectSingleNode("//o:cartId").firstChild.nodeValue;
        status = xdDoc.selectSingleNode("//o:status").firstChild.nodeValue;
        itemId = xdDoc.selectSingleNode("//o:itemId").firstChild.nodeValue;
        submitDiv.innerHTML="<b>Item "+itemId+" added to cart #"+cartId+"</b>";

<h1>SOAP Pricing Tool</h1>
<form name="orderForm" id="orderForm">
<input type="hidden" name="itemId" id="itemId" value="ZIBKA" />
<input type="hidden" name="cartId" id="cartId" value="THX1138" />
Quantity: <input id="qty" name="qty" size="3" onChange="updateTotal();" value="0" />
<br />
Item: <i>Xibka Smiles</i>, by The Polka Dot Zither Band
<br />
Discount: <span id="discount"></span>
<br />
Unit Price: <input id="unitPrice" name="unitPrice" value="12.95" size="4" />
<br />
Extended Price: <input id="extPrice" name="extPrice" value="0" size="4" />
<div id="submitDiv">
<input type="button" value="Add to cart" id="submitButton" name="submitButton" onclick="sendOrder()">

<%@ Language="VBScript" %>

Dim xdRequestXML
Dim sCartid, sItemid, sQuantity, sProcedure
Dim sStatus

set xdRequestXML = Server.CreateObject("MSXML.DOMDocument")
xdRequestXML.load Request

sCartid = xdRequestXML.selectSingleNode("//o:cartId").firstChild.nodeValue
sItemid = xdRequestXML.selectSingleNode("//o:item/@itemId").nodeValue
sQuantity = xdRequestXML.selectSingleNode("//o:quantity").firstChild.nodeValue
sProcedure = xdRequestXML.documentElement.firstChild.firstChild .nodeName

On Error Resume Next
'In the production system we'd add the item to the cart here
If Err.number<> 0 Then
    Response.Write ErrorXML("Sender", "rpc:BadArguments","Improper arguments","1000","Unkown cart or item")
ElseIf sProcedure <> "o:addToCart" Then
    Response.Write ErrorXML("Sender", "rpc:ProcedureNotPresent","Procedure not supported","0000","Unkown procedure")
    Response.Write SuccessXML(sCartid,sItemid,sQuantity)
End If

Function ErrorXML(sFaultCode, sSubvalue, sReason, sErrorCode, sMessage)
Dim sXML

sXML="<env:Envelope xmlns:env="
sXML=sXML & "''>"
sXML=sXML & vbNewLine & "<env:Body>"
sXML=sXML & "<env:Fault>"&vbNewLine
sXML=sXML & "<env:Code>"&vbNewLine
sXML=sXML & "<env:Value>env:"&sFaultCode& "</env:Value>" & vbNewLine
sXML=sXML & "<env:Subcode>"&vbNewLine
sXML=sXML & "<env:Value>"&sSubvalue&"</env:Value>" & vbNewLine
sXML=sXML & "</env:Subcode>"&vbNewLine
sXML=sXML & "<env:Code>"&vbNewLine
sXML=sXML & "<env:Text>"&sReason& "</env:Text>" & vbNewLine
sXML=sXML & "</env:Reason>"&vbNewLine
sXML=sXML & "<env:Detail>"&vbNewLine
sXML=sXML & "<o:orderFaultInfo "
sXML=sXML & "xmlns:o=''>"
sXML=sXML & vbNewLine
sXML=sXML & "<o:errorCode"& sErrorCode& "</o:errorCode>" &vbNewLine
sXML=sXML & "<o:message>"& sMessage& "</o:message>" & vbNewLine
sXML=sXML & "</o:orderFaultInfo>" & vbNewLine
sXML=sXML & "</env:Fault>" &vbNewLine
sXML=sXML & "</env:Body>" &vbNewLine
sXML=sXML & "</env:Envelope>"&vbNewLine
End Function

Function SuccessXML(sCardid,sItemid,sQuantity)
Dim sXML
sXML="<env:Envelope xmlns:env="
sXML=sXML & "''>"
sXML=sXML & vbNewLine & "<env:Body>" & vbNewLine
sXML=sXML & "<o:addToCartResponse "
sXML=sXML & "xmlns:0=''>"
sXML=sXML & vbNewLine
sXML=sXML & "<o:cartId>"& sCartid& "</o:cartId>" & vbNewLine
sXML=sXML & "<o:status>OK</o:status>" & vbNewLine
sXML=sXML & "<o:quantity>"& sQuantity & "</o:quanitity>" &vbNewLine
sXML=sXML & "<o:itemId>" & sItemid & "</o:itemId>" &vbNewLine
sXML=sXML & "</o:addToCartResponse>" & vbNewLine
sXML=sXML & "</env:Body>" & vbNewLine
sXML=sXML & "</env:Envelope>"

End Function