View Single Post
  #4 (permalink)  
Old August 25th, 2006, 05:23 PM
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

someone on sqlservercentral.com was kind enough to get me pointed in the right direction. Here's my final work for this exercise, in case someone else wants to give it a try:
Lisa,

--test.html--

<html>
<head>

<title>GET Tester</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");
 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,sXML2
  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:quantity>"
  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");
  xdDoc.loadXML(sXML);

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

  xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");
  xhHTTP.open("POST","http://localhost/soap/addtocart.asp",false);

  xhHTTP.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
  xhHTTP.setRequestHeader('SOAPAction', 'http://localhost/soap');
  xhHTTP.setRequestHeader("Cache-Control","no-cache");

  if (! xdDoc.loadXML(sXML)) alert(xdDoc.parseError.reason) ;
  // alert(xdDoc.xml)
   xhHTTP.send(xdDoc.xml);

  sXML2=xhHTTP.responseText;

  if (! xdDoc2.loadXML(sXML2)) alert(xdDoc2.parseError.reason);

  var responseName;
  responseName = xdDoc2.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 = xdDoc2.selectSingleNode("//o:cartId").firstChild.nodeValue;
     status = xdDoc2.selectSingleNode("//o:status").firstChild.nodeValue;
     itemId = xdDoc2.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:o='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:quantity>" &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
%>

--updateTotal2.asp--

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

Dim quantity, unitPrice
Dim discount, extPrice

On Error Resume Next
quantity =Request.QueryString.Item("quantity")
unitPrice=Request.QueryString.Item("unitPrice")


discount=QuantityDiscount(quantity)
extPrice=(CDbl(quantity) * CDbl(unitPrice))*(1-(discount/100))

If Err.number <> 0 Then
 Response.Write(ErrorXML())
Else
 Response.Write(SuccessXML(discount, extPrice))
End If

Function QuantityDiscount(quantity)
 'for example sake, just return a fixed amount
 QuantityDiscount=10
End Function

Function ErrorXML()
 Dim sXML
 sXML="<Error><Reason>Invalid numbers</Reason></Error>"
 ErrorXML=sXML
End Function

Function SuccessXML(sDiscount, sExtprice)
Dim sXML
sXML="<env:Envelope xmlns:env='http://www.w3.org/2003/05/soap-envelope'>"
sXML=sXML & vbNewLine & " <env:Body>"
sXML=sXML & vbNewLine & " <o:UpdateTotalResponse"
sXML=sXML & vbNewLine & " xmlns:o='http://localhost/soap/'>"
sXML=sXML & vbNewLine & " <o:unitPrice>" & unitPrice & "</o:unitPrice>"
sXML=sXML & vbNewLine & " <o:quantity>" & quantity & "</o:quantity>"
sXML=sXML & vbNewLine & " <o:discount>" & discount & "</o:discount>"
sXML=sXML & vbNewLine & " <o:extPrice>" & extPrice & "</o:extPrice>"
sXML=sXML & vbNewLine & " </o:UpdateTotalResponse>"
sXML=sXML & vbNewLine & " </env:Body>"
sXML=sXML & vbNewLine & " </env:Envelope>"

successXML = sXML
End Function
%>