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");
xdDoc.loadXML(sXML);
xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");
xhHTTP.open("POST","http://localhost/soap/submitOrder1.asp",false);
xhHTTP.send(xdDoc);

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!

---soapclient.html
<html>
<head>
<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)
    xhHTTP.open("GET","http://localhost/soap/updateTotal2.asp?quantity="+qty+"&unitPrice="+unit Price, false);
    xhHTTP.send();
    xdDoc=xhHTTP.responseXML;
    var discount, extPrice;
    discount=xdDoc.selectSingleNode("//o:discount").text + "% off";
    extPrice=xdDoc.selectSingleNode("//o:extPrice").text;
    document.getElementById("discount").innerHTML=disc ount;
    orderForm.extPrice.value=extPrice;
}

function sendOrder() {
    var xdDoc, xhHTTP, sXML
    sXML="<env:Envelope xmlns:env="
    sXML=sXML + "'http://www.w3.org/2003/05/soap-envelope'>"
    sXML=sXML + "<env:Body>"
    sXML=sXML + "<o:addToCart "+
        "xmlns:o='http://www.sernaferna.com/soap/ordersystem'>";
    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>";
    alert(sXML)

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

    xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");
    xhHTTP.open("POST","http://localhost/soap/submitOrder1.asp",false);
alert(xhHTTP.responseXML);
    xhHTTP.send(xdDoc);
    alert(xhHTTP.responseXML);
    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;
        message=xDoc.selectSingleNode("//o:message").firstChild.nodeValue;
        alert(reason+":\n"+message);
    } 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>";
    }

}
</script>
</head>
<body>
<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()">
</div>
</form>
</body>
</html>

--addtocart.asp
<%@ Language="VBScript" %>
<%
Response.ContentType="text/xml"

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")
Else
    Response.Write SuccessXML(sCartid,sItemid,sQuantity)
End If


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

sXML="<env:Envelope xmlns:env="
sXML=sXML & "'http://schemas.xmlsoap.org/soap/envelope/'>"
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='http://www.sernaferna.com/soap/ordersystem'>"
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
ErrorXML=sXML
End Function

Function SuccessXML(sCardid,sItemid,sQuantity)
Dim sXML
sXML="<env:Envelope xmlns:env="
sXML=sXML & "'http://www.w3.org/2003/05/soap-envelope'>"
sXML=sXML & vbNewLine & "<env:Body>" & vbNewLine
sXML=sXML & "<o:addToCartResponse "
sXML=sXML & "xmlns:0='http://www.sernaferna.com/soap/ordersystem'>"
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>"

SuccessXML=sXML
End Function
%>