Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: Beginning XML 3rd Edition
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning XML 3rd Edition
This is the forum to discuss the Wrox book Beginning XML, 3rd Edition by David Hunter, Andrew Watt, Jeff Rafter, Jon Duckett, Danny Ayers, Nicholas Chase, Joe Fawcett, Tom Gaven, Bill Patterson; ISBN: 9780764570773
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning XML 3rd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 23rd, 2006, 10:19 AM
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
%>

  #2 (permalink)  
Old August 23rd, 2006, 11:53 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If that is the exact code then there is a capitalisation error in the sendOrder function:
Code:
sXML=sXML + "<o:extPrice>"+orderForm.extPrice.value+"</o:extPrice>";
    sXML=sXML + "</O:item>";
    sXML=sXML + "</o:addToCart>";
=>

Code:
sXML=sXML + "<o:extPrice>"+orderForm.extPrice.value+"</o:extPrice>";
    sXML=sXML + "</o:item>";
    sXML=sXML + "</o:addToCart>";
--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old August 23rd, 2006, 12:01 PM
Registered User
 
Join Date: Aug 2006
Location: Chippewa Falls, WI, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,

Thanks for spotting my typo. However, I'm still getting the same error message I posted originally :(

I've read a bunch of different postings ranging from sharing my localhost to syntax and have not come across a solution...yet. I've got to get through this to begin writing my own web service.

Kim

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


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing soap message neerom XSLT 3 November 17th, 2008 07:32 AM
need way to pass the soap message to webservice i raju_kmarhotmail.com .NET Web Services 0 November 3rd, 2007 03:19 AM
Chap 15 (p.579) Connection string to SQL Server Venboy BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 July 23rd, 2006 10:56 AM
Posting SOAP request to third party vendor finny.net .NET Web Services 4 January 24th, 2005 03:16 AM
SOAP Message hueduongit .NET Web Services 4 December 1st, 2003 08:46 PM



All times are GMT -4. The time now is 04:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.