Archive for September, 2009

initialize soap from ASP

September 23, 2009

Soap doesn’t like relative paths, but I want to create a path string so that my code runs both locally and on the server.

' 1) web service setup
dim servername
servername = request("SERVER_NAME")

dim strSoapObjectLibrary

if ( lcase(servername) = "localhost" ) then
strSoapObjectLibrary = "MSSOAP.SoapClient" ' works on WinXP
else
strSoapObjectLibrary = "MSSOAP.SoapClient30" ' change this to match whatever library is installed
end if

SET svc = Server.CreateObject(strSoapObjectLibrary)
svc.ClientProperty("ServerHTTPRequest") = True

' make the path to the web service somewhat dynamically
dim sPath
if ( lcase(servername) = "localhost" ) then
sPath = "http://localhost"
else
sPath = "https://" + servername ' change this to match whatever library is installed
end if

sPath = sPath + "/WQQQ2/ws/wsQuotes.asmx"
sPath = sPath + "?WSDL"
'response.Write(sPath)

Call svc.mssoapinit(sPath,"wsQuotes")

Advertisements

web service to return html , javascript converts return string

September 18, 2009

I had to make a kind of “quote of the day” web service. Then I changed it so that the returned text could be html formatted instead of just plain text.

That caused a problem for me, because while the html saved in my database looked good (bolds and line feeds etc), when my calling routine got the text out of the web service, it converted all the less than signs to < and the greater than signs to >.

I don’t know if this is a good solution, but here’s what it does:
INPUT STRING:

<?xml version=”1.0″ encoding=”utf-8″?>
<string xmlns=”http://tempuri.org/”>Yabba Dabba Doo.
&lt;br&gt;&lt;br&gt;

&lt;bold&gt;Fred Flintstone&lt;/bold&gt;</string>

OUTPUT STRING:

Yabba Dabba Doo.
<br><br>

<bold>Fred Flintstone</bold>

Here’s the routine:

 


// ---------------------------------------------------
// purpose - does a simple parse of the xml response to get the string we're interested in
function ajaxws_get_response_html(sXML) {
var sResponseText;
var iFirst = sXML.indexOf('org/">') + 6;
var iLast = sXML.indexOf('', iFirst);
sResponseText = sXML;

if (iFirst > 0 && iLast > 0) {
var iLength = iLast - iFirst;
sResponseText = sXML.substr(iFirst, iLength);
}

sResponseText = sResponseText.replace(/</g, '');
return sResponseText;
}

 

Here is where it fits into the set of routines to call a web service from the browser:

 

 

// purpose – ajax like routines to get data from the web service
var xmlhttp = null; // the init function will set this, it is the xml object that calls the server side function

var sReturned_Data;
sReturned_Data = ”;

var url_base = ”;
url_base = ‘ws/wsquotes.asmx/GetQuote’; // syntax for non-soap url
var debugjs;
debugjs = 0; // set the debug variable to 0 to turn off the alert messages
if (debugjs > 3) alert(‘page loaded, ajax_updater’);

// —————————————————
// purpose – try to guarantee that the activex object gets instantiated
// if ajax is not initiated when we call it the first time, then this sub makes sure that it gets initiated
function ajaxws_Init() {
try {
// Mozilla / Safari
xmlhttp = new XMLHttpRequest();
}
catch (e) {
// Explorer
var _ieModelos = new Array(
‘MSXML2.XMLHTTP.5.0’,
‘MSXML2.XMLHTTP.4.0’,
‘MSXML2.XMLHTTP.3.0’,
‘MSXML2.XMLHTTP’,
‘Microsoft.XMLHTTP’);

var success = false;
for (var i = 0; i 0) alert(‘ajaxws_CallWebServiceUpdater – id:’ );
if (debugjs > 0) alert(‘ajaxws_CallWebServiceUpdater – url:’ );

xmlhttp.open(“GET”, url, true);
xmlhttp.onreadystatechange = ajaxws_stateChanged; // http://snippets.dzone.com/tag/xmlhttp
xmlhttp.send(null);
// http://www.devguru.com/technologies/xmldom/QuickRef/obj_httpRequest.html
}

// —————————————————
// purpose – called by ajax event
function ajaxws_stateChanged() {
if (debugjs > 0) alert(‘ajaxws_stateChanged ‘);

if (xmlhttp.readyState == 4 || xmlhttp.readyState == “complete”) {
sReturned_Data = ajaxws_get_response_html(xmlhttp.responseText);
}
}

// —————————————————
// purpose – does a simple parse of the xml response to get the string were interested in
function ajaxws_get_response_text(sXML) {
return sXML;
var sResponseText;
var iFirst = sXML.indexOf(‘/”>’) + 3;
var iLast = sXML.indexOf(‘ 0 && iLast > 0) {
var iLength = iLast – iFirst;
sResponseText = sXML.substr(iFirst, iLength);
}
return sResponseText;
}

// —————————————————
// purpose – does a simple parse of the xml response to get the string we’re interested in
function ajaxws_get_response_html(sXML) {
var sResponseText;
var iFirst = sXML.indexOf(‘org/”>’) + 6;
var iLast = sXML.indexOf(”, iFirst);
sResponseText = sXML;

if (iFirst > 0 && iLast > 0) {
var iLength = iLast – iFirst;
sResponseText = sXML.substr(iFirst, iLength);
}

sResponseText = sResponseText.replace(/</g, ”);
return sResponseText;
}

(more…)