ASP - question for robbe morris - Asked By top ramen on 20-Jul-14 12:37 AM

i've been playing around with a way to display stock quotes in a web page

i read an article on this site showing how to do it in c# - i am trying to be able to do it in classic asp though

then i noticed that you have a webservice that returns a stock quote based on a stock symbol sent in as a parameter

"well," thought i, "i've played with webservices before in classic asp using rope - this should be as slick as snot"

wrong - the last time i tried to do this in asp, i used a url (or uri) to get at the sdl of a webservice in the format: http://www.domain.com/webservice.asmx?sdl

rope then used the sdl returned to create a proxy object and then i was able to access the methods, properties, etc., of the webservice

however, your stock quote webservice, in accordance with the .net beta 2 specs, requires the format: http://www.domain.com/webservice.asmx?wsdl to obtain the sdl

this works fine for me when i pull it up in the browser - however, i am getting an error when i try to use it in code

so, is the new wsdl format different than the old sdl? my rope object doesn't seem to like it much - any ideas?

here's my function that grabs the stock quote, btw, in case you'd like to take a look:

..........................................
function GetWebServiceResponse(byval sSymbol)
	ON ERROR RESUME NEXT

	dim oRP
	dim vResult
	const icURI = 1
	const sURI = "http://www.eggheadcafe.com/WebServices/stockquote/stockquote.asmx?wsdl"
	
	sSymbol = UCase(sSymbol)
	
	set oRP = Server.CreateObject("ROPE.Proxy")
	if oRP.LoadServicesDescription(icURI, sURI) = 0 then
		vResult = "Failed to load the WebService's SDL into ROPE.Proxy object."
	else
		vResult = oRP.GetQuote(sSymbol)
	end if

	set oRP = nothing
	
	if Err.Number <> 0 then
		GetWebServiceResponse = _
			"<span class=""ErrorFont"">" & _
			"There was an error.<br>" & _
			"Number: " & Err.number & "<br>" & _
			"Description: " & Err.Description & _
			"</span>"
	else
		GetWebServiceResponse = vResult
	end if
end function
..........................................

Sorry...I use straight SOAP and XMLHttp... - Asked By Robbe Morris on 08-Aug-01 12:52 PM

...I don't play with the SOAP toolkit.  I like to create my own SOAP envelopes/messages.

What is the real web service for the stock quote you are going after so I can look at it?  The one at the top of the page just tears out the HTML from http://www.nasdaq.com with straight ASP/XMLHttp.

i was using... - Asked By top ramen on 08-Aug-01 01:19 PM

...a url mentioned somewhere on your site (i can't remember where now): http://www.eggheadcafe.com/WebServices/stockquote/stockquote.asmx?wsdl

so, is that sdl something you wrote yourself? and it's possibly not kosher? hmmmm...

i'll dig around and see if i can find another webservice or xml feed somewhere

btw, the error i was getting was:

Number: -4000
Description: Error calling LoadServicesDescription method: Unable to process the service description data loaded from the specified URI. http://www.eggheadcafe.com/WebServices/stockquote/stockquote.asmx?wsdl

I don't think Peter's web service... - Asked By Robbe Morris on 08-Aug-01 01:27 PM

...was designed for other people to access it.
I think he designed that page as a client side .NET page that ran the web service inside the C# class.  I'd have to double check the code though.

Download his code.  I think he references Yahoo's stock streamer.  I'm assuming you know how to use XMLHttp.  Just in case you don't, there is a WhoIs example in Tips & Tricks.  All Pete does is strip out the HTML returned.  Nothing special that can't be done in straight ASP.
i'll give that a try - thanks <eop> - Asked By top ramen on 08-Aug-01 01:41 PM
.
here's some code for you - Asked By top ramen on 08-Aug-01 04:57 PM
this works beautifully using xmlhttp

my solution uses two files, "stockquotews.asp", and "stockquotes1.xsl"

rather than explain the code (which is pretty self-explanatory anyway), i've decided to include it all below:

STOCKQUOTEWS.ASP
====================================================
<%OPTION EXPLICIT%>

<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim sResponse
dim sSymbol

sSymbol = UCase(Trim(Request.Form("txtSymbol")))

if Trim(Request.Form("SUBMITTED")) = "TRUE" then
  sResponse = GetWebServiceResultsViaXMLHTTP(sSymbol)
else
  sResponse = "Request not yet submitted."
end if
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function GetWebServiceResultsViaXMLHTTP(byval sSymbol)
  dim oXMLHTTP
  dim sResult
  dim sXML
  dim sURL
  
  sURL = "http://www.eggheadcafe.com/WebServices/stockquote/stockquote.asmx/GetQuote?symbol=" & sSymbol
  
  set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  oXMLHTTP.open "GET", sURL, false
  oXMLHTTP.send
  sXML = oXMLHTTP.responseXML.xml
  set oXMLHTTP = nothing
  
  'Format it to be true XML format
  sXML = Replace(Replace(Replace(Replace(sXML, "<", "<"), ">", ">"), "<string xmlns=""http://tempuri.org/"">", ""), "</string>", "")
  
  'Transform the XML
  sResult = TransformXML(sXML, Server.MapPath("stockquotes1.xsl"))
  
  GetWebServiceResultsViaXMLHTTP = sResult
end function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function TransformXML(byval sXML, byval sXSLFilePath)
  dim oXMLDoc
  dim oXSLDoc
  dim sResult
  
  set oXMLDoc = Server.CreateObject("MSXML2.DOMDocument")
  oXMLDoc.async = false
  if oXMLDoc.loadXML(sXML) then
    set oXSLDoc = Server.CreateObject("MSXML2.DOMDocument")
    oXSLDoc.async = false
    if oXSLDoc.load(sXSLFilePath) then
      sResult = oXMLDoc.transformNode(oXSLDoc)
    else
      sResult = "<span class=""ErrorFont"">Failed to load XSL string into MSXML2.DOMDocument object.</span>"
    end if
    set oXSLDoc = nothing
  else
    sResult = "<span class=""ErrorFont"">Failed to load XML string into MSXML2.DOMDocument object.</span>"
  end if
  set oXMLDoc = nothing
  
  TransformXML = sResult
end function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>

<html>
<head>
  <title>Stock Quote WebService Access Test</title>
  <style>
    .NormalFont{
      font-family: arial, helvetica, verdana;
      font-size: 10pt;
    }
    .ErrorFont{
      font-family: arial, helvetica, verdana;
      font-size: 10pt;
      color: #cc0000;
    }
  </style>
</head>
<body onLoad="window.document.frmMain.txtSymbol.focus();">

<form id="frmMain" name="frmMain" method="post" action="stockquotews.asp">
<input type="hidden" name="SUBMITTED" value="TRUE">

<table border="0" cellspacing="0" cellpadding="0" align="center" style="border:1px solid #000000; padding:10px 10px 10px 10px;">
<tr>
  <td class="NormalFont"><b>Enter Ticker Symbol:</b></td>
</tr>
<tr>
  <td class="NormalFont">
    <input type="text" id="txtSymbol" name="txtSymbol" value="<%=sSymbol%>" size="5" maxlength="5">
    <input type="submit" id="subSubmit" name="subSubmit" value="Submit">
  </td>
</tr>
<tr>
  <td class="NormalFont">
    <b>Response:</b>
    <br><br>
    <%=sResponse%>
  </td>
</tr>
</table>

</form>

</body>
</html>
====================================================


STOCKQUOTES1.XSL
====================================================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" />

<!--
NOTE: The XML to be transfor