Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 03:54 PM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML and SOAP

using sample code from beginning xml, ran both prior examples on a true web server to web device configuration fine! When i run this last example it always fails on line 27, with the message
'invalid character line 27, char 1, system error -1072896659'
which is the send i.e. "hhttp.send(xddoc);"
huh?

html
---------------
<html><head><title>Post Tester</title>
<script language = "JavaScript">
function dopost()
{
var xddoc, xhhttp, sxml

sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=";
sxml = sxml + "'http://schemas.xmlsoap.org/soap/envelope/'>\n";
sxml = sxml + " <SOAP-ENV:Body>\n";
sxml = sxml + " <an:addnumbers";
sxml = sxml + " xmlns:an='http://www.3zwireless.com/addnumbers/'>\n";
sxml = sxml + " <an:numone>";
sxml = sxml + numone.value;
sxml = sxml + " </an:numone>\n";
sxml = sxml + " <an:numtwo>";
sxml = sxml + numtwo.value;
sxml = sxml + " </an:numtwo>\n";
sxml = sxml + " <an:addnumbers>\n";
sxml = sxml + " </SOAP-ENV:Body>\n";
sxml = sxml + "</SOAP-ENV:Envelope>";

xddoc = new ActiveXObject("MSXML.DOMDocument");
xddoc.loadXML(sxml);
xhhttp = new ActiveXObject("MSXML2.XMLHTTP");
xhhttp.open("POST", "http://www.3zwireless.com/addnumbers3.asp", false);
xhhttp.setRequestHeader("SOAPAction", "http://www.3zwireless.com/addnumbers#addnumbers");
xhhttp.send(xddoc);
xddoc = xhhttp.responseXML;

if (xddoc.documentElement.firstChild.firstChild.nodeN ame == "Fault")
 {
 alert("bad numbers passed");
 }
else
 {
 alert(xddoc.documentElement.firstChild.firstChild. text);
 }
}
</script>
</head>
<body>
<p>number 1:<input id=numone name=numone><p>
<p>number 2:<input id=numtwo name=numtwo><p>
<input type="button" value="POST" id=btnpost name=btnpost onclick="dopost()"
</body>
</html>
------------------
.asp page
------------------
<%@ Language=VBSCRIPT%>
<%
Response.ContentType = "text/xml"
Response.AddHeader "SOAPAction",
"http://www.3zwireless.com/addnumbers#addnumbersresult"

Dim xdrequestxml
Dim snumber1, snumber2
Dim nresult

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

snumber1 = xdrequestxml.documentElement.firstChild.firstChild .firstChild.text
snumber2 = xdrequestxml.documentElement.firstChild.firstChild .lastChild.text

On Error Resume Next
nresult = CLng(snumber1) + CLng(snumber2)

If Err.number <> 0 Then
    Response.Write ErrorXML("Client", "Invalid Numbers", snumber1, snumber2)
ElseIf Request.ServerVariables("HTTP_SOAPAction") <> "http://www.3zwireless.com/addnumbers#addnumbers" Then
    Response.Write ErrorXML("Client", "Procedure not understood", Request.ServerVariables("SOAPAction"), snumber2)
Else
    Response.Write SuccessXML(nresult)
End If

Function ErrorXML(sfaultcode, sfaultstring, snumone, snumtwo)
   Dim sxml
   sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="
   sxml = smxl & "'http://schemas.xmlsoap.org/soap/envelope/'>"
   sxml = smxl & vbNewLine & "<SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "<SOAP-ENV:Fault>" & vbNewLine
   sxml = smxl & "<faultcode>soap:" & sfaultcode & "</faultcode>" & vbNewLine
   sxml = smxl & "<faultstring>" & sfaultstring & "</faultstring>" & vbNewLine
   sxml = smxl & "<faultfactor>http://www.3zwireless.com/addnumbers3.asp</faultfactor>" & vbNewLine
   sxml = smxl & "<detail>": & vbNewLine
   sxml = smxl & "<an:addnumbersdetail "
   sxml = smxl & "xmlns:an='http://www.3zwireless.com/addnumbers/'>" & vbNewLine
   sxml = smxl & "<an:numone>" & snumone & "</an:numone> & vbNewLine
   sxml = smxl & "<an:numtwo>" & snumtwo & "</an:numtwo> & vbNewLine
   sxml = smxl & "</an:addnumbersdetail>" & vbNewLine
   sxml = smxl & "</detail> & vbNewLine
   sxml = smxl & "</SOAP-ENV:Fault>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Envelope>"
   ErrorXML = sxml
End Function

Function SuccessXML(sresult)
   Dim sxml
   sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="
   sxml = smxl & "'http://schemas.xmlsoap.org/soap/envelope/'>"
   sxml = smxl & vbNewLine & "<SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "<an:addnumbersresponse "
   sxml = smxl & "xmlns:an='http://www.3zwireless.com/addnumbers'>"
   sxml = smxl & vbNewLine
   sxml = smxl & "<response>" & sresult & "</response>" & vbNewLine
   sxml = smxl & "</an:addnumbersresponse>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Envelope>"
  SuccessXML = sxml
End Function

%>




 
Old March 4th, 2004, 05:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I haven't tested all of this but there is a typo in the part that builds the xml string (an:addnumbers tag is not closed properly, replace it with this which is written in more compact JavaScript:
Code:
sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="
     + "'http://schemas.xmlsoap.org/soap/envelope/'>\n"
     + " <SOAP-ENV:Body>\n"
     + "     <an:addnumbers"
     + "   xmlns:an='http://www.3zwireless.com/addnumbers/'>\n"
     + "     <an:numone>" + numone.value + " </an:numone>\n"
     + "     <an:numtwo>"+ numtwo.value + " </an:numtwo>\n"
     + "     </an:addnumbers>\n"
     + " </SOAP-ENV:Body>\n"
     + "</SOAP-ENV:Envelope>";
Joe (Microsoft MVP - xml)
 
Old March 5th, 2004, 11:26 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Joe,

that corrected one of a few bugs, got this sample SOAP app up and running. Now that my interest is peaked. Perhaps you could shed some more light to a "beginner" in XML/SOAP development.

It looks like you need to have the "soap-server" in VB as to get hooks into the XML parser. i.e. It does not seem like you could write a SOAP server on a .ASP page in pure JavaScript?

Is there a free tool out there to trace HTTP Gets/Posts (i am in the windows env). I downloaded something called the IIS6.0 Resource toolkit the other day , but i need to upgrade my box to XP Pro instead of XP Home. Of course the Web Server is on another box entirely. If familar with the iis6.0 resource toolkit does this let you trace from the browser side?

thanks again!


 
Old March 5th, 2004, 12:28 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If I understand correctly you want to write an asp page to receive the sop message from the client and process it?
You can either parse it manually using the xml parser or for a much easier way use the Microsoft soap toolkit
http://www.microsoft.com/downloads/d...displaylang=en

Here's an example of usage. You need COM class that does something rather the book example that manually parsees the integers out and adds them.

http://www.perfectxml.com/articles/xml/hellosoap.asp

--

Joe
 
Old March 5th, 2004, 12:34 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You may also want to search for WFETCH on msdn.com, a tracing tool for http requests.

--

Joe
 
Old March 10th, 2004, 07:08 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,

The wfetch tool is in the iis 6.0 toolkit I downloaded. I don't mind rolling my own, I just need a better debug environment. I ended up shooting SOAP packets from an IPAQ 5555 up to a web server using the Inetxxxx() interface from windows ce/mobile!

many thanks!


 
Old August 23rd, 2006, 10:58 AM
Registered User
 
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've been having the same error message with an exercise from Beginning XML (p.579-586). Thought I'd try your html and asp to see if I could successfully execute. Could you post your final code?

I tried Joe's suggestion and it didn't correct the problem.

Thanks!

My source files (located C:\Inetpub\wwwroot\soap)
--add.html--
<html><head><title>Post Tester</title>
<script language = "JavaScript">
function dopost()
{
var xddoc, xhhttp, sxml

sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="
     + "'http://schemas.xmlsoap.org/soap/envelope/'>\n"
     + " <SOAP-ENV:Body>\n"
     + " <an:addnumbers"
     + " xmlns:an='http://localhost/soap/'>\n"
     + " <an:numone>" + numone.value + " </an:numone>\n"
     + " <an:numtwo>"+ numtwo.value + " </an:numtwo>\n"
     + " </an:addnumbers>\n"
     + " </SOAP-ENV:Body>\n"
     + "</SOAP-ENV:Envelope>";

xddoc = new ActiveXObject("MSXML.DOMDocument");
xddoc.loadXML(sxml);

xhhttp = new ActiveXObject("MSXML2.XMLHTTP");
xhhttp.open("POST", "http://localhost/soap/addnumbers3.asp", false);
xhhttp.setRequestHeader("SOAPAction", "http://localhost/soap/addnumbers#addnumbers");

xhhttp.send(xddoc);
xddoc = xhhttp.responseXML;

if (xddoc.documentElement.firstChild.firstChild.nodeN ame == "Fault")
 {
 alert("bad numbers passed");
 }
else
 {
 alert(xddoc.documentElement.firstChild.firstChild. text);
 }
}
</script>
</head>
<body>
<p>number 1:<input id=numone name=numone><p>
<p>number 2:<input id=numtwo name=numtwo><p>
<input type="button" value="POST" id=btnpost name=btnpost onclick="dopost()"
</body>
</html>

--addnumbers3.asp--
<%@ Language=VBSCRIPT%>
<%
Response.ContentType = "text/xml"
Response.AddHeader "SOAPAction",
"http://localhost/soap/addnumbers#addnumbersresult"


Dim xdrequestxml
Dim snumber1, snumber2
Dim nresult

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

snumber1 = xdrequestxml.documentElement.firstChild.firstChild .firstChild.text
snumber2 = xdrequestxml.documentElement.firstChild.firstChild .lastChild.text

On Error Resume Next
nresult = CLng(snumber1) + CLng(snumber2)

If Err.number <> 0 Then
    Response.Write ErrorXML("Client", "Invalid Numbers", snumber1, snumber2)
ElseIf Request.ServerVariables("HTTP_SOAPAction") <> "http://localhost/addnumbers#addnumbers" Then
    Response.Write ErrorXML("Client", "Procedure not understood", Request.ServerVariables("SOAPAction"), snumber2)
Else
    Response.Write SuccessXML(nresult)
End If

Function ErrorXML(sfaultcode, sfaultstring, snumone, snumtwo)
   Dim sxml
   sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="
   sxml = smxl & "'http://schemas.xmlsoap.org/soap/envelope/'>"
   sxml = smxl & vbNewLine & "<SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "<SOAP-ENV:Fault>" & vbNewLine
   sxml = smxl & "<faultcode>soap:" & sfaultcode & "</faultcode>" & vbNewLine
   sxml = smxl & "<faultstring>" & sfaultstring & "</faultstring>" & vbNewLine
   sxml = smxl & "<faultfactor>http://www.3zwireless.com/addnumbers3.asp</faultfactor>" & vbNewLine
   sxml = smxl & "<detail>": & vbNewLine
   sxml = smxl & "<an:addnumbersdetail "
   sxml = smxl & "xmlns:an='http://www.3zwireless.com/addnumbers/'>" & vbNewLine
   sxml = smxl & "<an:numone>" & snumone & "</an:numone> & vbNewLine
   sxml = smxl & "<an:numtwo>" & snumtwo & "</an:numtwo> & vbNewLine
   sxml = smxl & "</an:addnumbersdetail>" & vbNewLine
   sxml = smxl & "</detail> & vbNewLine
   sxml = smxl & "</SOAP-ENV:Fault>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Envelope>"
   ErrorXML = sxml
End Function

Function SuccessXML(sresult)
   Dim sxml
   sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="
   sxml = smxl & "'http://schemas.xmlsoap.org/soap/envelope/'>"
   sxml = smxl & vbNewLine & "<SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "<an:addnumbersresponse "
   sxml = smxl & "xmlns:an='http://www.3zwireless.com/addnumbers'>"
   sxml = smxl & vbNewLine
   sxml = smxl & "<response>" & sresult & "</response>" & vbNewLine
   sxml = smxl & "</an:addnumbersresponse>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Body>" & vbNewLine
   sxml = smxl & "</SOAP-ENV:Envelope>"
  SuccessXML = sxml
End Function

%>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Soap Pricing Tool in XML for Beginners wsessoms XML 3 December 9th, 2006 05:33 AM
MS Access SOAP or XML Functionality BrianWren Access 1 May 4th, 2006 06:51 AM
transfer xml file to specified location using soap rjkulkarni2001 .NET Web Services 0 April 4th, 2006 08:13 AM
How to: ASP, XML and SOAP hotfridge XML 0 February 18th, 2004 12:15 AM
Soap and xml bearpaws XML 2 November 16th, 2003 06:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.