Solved

calling a .net web service from classic ASP page

Posted on 2003-11-05
11
703 Views
Last Modified: 2008-03-10
How can i can call a .net web service from an ASP page? are there any sites/sources that i can check this out on?

I need to see how this is done via ASP(preferably in vbscript), not ASP.net. I can only find samples on th einternet using ASP.net. I am much more familiar with using using web services in vb.net, but not aware of how to do this using classic ASP.

Any help appreciated thanks

0
Comment
Question by:mikeandbee
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 4

Expert Comment

by:1mak
ID: 9685427
Here's an article that takes you through the process...

Basically, you open the webservice, passing your parameters as a querystring, and parse the resultant XML all using the Microsoft XMLHTTP class.
0
 

Author Comment

by:mikeandbee
ID: 9685560
i think you forgot to paste the actual article in your comment, not? Could you please re-post.

thanks
0
 

Author Comment

by:mikeandbee
ID: 9686137
i need to see that article, i presume it shows the code behind how to do this in vbscript?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 4

Expert Comment

by:1mak
ID: 9686681
Really sorry mikeandbee, rookie mistake...

http://www.aspfree.com/articles/576,1/articles.aspx
0
 
LVL 17

Expert Comment

by:Squeebee
ID: 9690867
I don't use ASP, but PocketSOAP works extremely well for me in plain old VB-land.

http://www.pocketsoap.com/pocketsoap/
0
 

Author Comment

by:mikeandbee
ID: 9693205
i really need an example where I can send an XML request to the web service. The example given just sends a request like so:
SoapRequest.Open "GET",SoapURL , False
SoapRequest.Send()
But I actually want to send an XML string inside this request. Can you show me an example fo this? And how would i handle the response?
thanks
0
 
LVL 1

Accepted Solution

by:
rychs earned 500 total points
ID: 9695042
Hello
  Here is an example using Google's beta search service. This code is for client-side but it could easily be switched to server-side using JScript.

<script language="JavaScript">
function searchFor(arg)
{      
      objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
      try
      {
            objHTTP.open("post", "http://api.google.com/search/beta2", false);
      }
      catch(error)
      {
            if(error.description == "Permission denied" || error.description == "Access is denied")
            {
                  var msg = "Your current security settings prevent access to this web service.<br>"
                  msg = msg + "To enable this service:<br>1. Go to the Tools menu and select Internet Options<br>"
                  msg = msg + "2. Click the security tab at the top of the page<br> 3. Click the Custom Level button<br>"
                  msg = msg + "3. Find the topic 'Access Data Sources Across Domains' and set it to prompt<br>"
                  msg = msg + "4. Click OK and then OK again and you will be able to access the web service<br><br>"
                  msg = msg + "OR <a style='cursor:hand;text-decoration:underline;' onclick='window.open(\"GoogleWebService.asp?arg=" + arg + "\", \"\", \"width=300,height=300,toolbar=no,scrollbars=yes\")'>"
                  msg = msg + "Click here</a> to view the results in a new window<br><br>"
                  msg = msg + "<a style='cursor:hand' onclick=google.style.display='none';return false;>Close Window</a>"
                  
                  google.innerHTML = msg;
                  google.style.top =  document.body.scrollTop + 10
                  google.style.display = "block";
                  
            }
            return false;
      }
      objHTTP.setRequestHeader("Content-Type", "text/xml");
      
      strEnvelope = "<?xml version='1.0' encoding='UTF-8'?>";
      strEnvelope = strEnvelope + "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' ";
      strEnvelope = strEnvelope + "xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' ";
      strEnvelope = strEnvelope + "xmlns:xsd='http://www.w3.org/1999/XMLSchema'>";
      strEnvelope = strEnvelope + "<SOAP-ENV:Body>";
      strEnvelope = strEnvelope + "<ns1:doGoogleSearch xmlns:ns1='urn:GoogleSearch' ";
      strEnvelope = strEnvelope + "SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>";
      strEnvelope = strEnvelope + "<key xsi:type='xsd:string'></key>";
      strEnvelope = strEnvelope + "<q xsi:type='xsd:string'>" + arg + "</q>";
      strEnvelope = strEnvelope + "<start xsi:type='xsd:int'>0</start>";
      strEnvelope = strEnvelope + "<maxResults xsi:type='xsd:int'>10</maxResults>";
      strEnvelope = strEnvelope + "<filter xsi:type='xsd:boolean'>true</filter>";
      strEnvelope = strEnvelope + "<restrict xsi:type='xsd:string'></restrict>";
      strEnvelope = strEnvelope + "<safeSearch xsi:type='xsd:boolean'>false</safeSearch>";
      strEnvelope = strEnvelope + "<lr xsi:type='xsd:string'></lr>";
      strEnvelope = strEnvelope + "<ie xsi:type='xsd:string'>latin1</ie>";
      strEnvelope = strEnvelope + "<oe xsi:type='xsd:string'>latin1</oe>";
      strEnvelope = strEnvelope + "</ns1:doGoogleSearch>";
      strEnvelope = strEnvelope + "</SOAP-ENV:Body>";
      strEnvelope = strEnvelope + "</SOAP-ENV:Envelope>";
      
      //********** Google **********************
      objHTTP.send(strEnvelope);
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      var temp = unescape(objHTTP.responseText)
      xmlDoc.loadXML(temp);
      titleNodes = xmlDoc.getElementsByTagName("title");
      urlNodes = xmlDoc.getElementsByTagName("URL");

      var holder = "<span style='cursor:hand;position:absolute;left:100;' onClick=google.style.display='none';>Close Window</span><br>"
      for(i=0;i < urlNodes.length;i++)
      {
            holder = holder + (i + 1) + ".<a href='" + urlNodes.item(i).text + "' target='_blank'>&nbsp;"
            holder = holder + titleNodes.item(i).text + "</a><br>"
      }
      google.innerHTML = holder;
      google.style.top =  document.body.scrollTop + 10
      google.style.display = "block";
}
</script>

It won't work because I removed the key value that google gave me. If you want to test it, request a key from google's site.

Hope this helps
0
 
LVL 1

Expert Comment

by:stephenmmitchell
ID: 10786418
Below is a link to a text file called SoapTools.asp.

You can include that script into your asp file and use the example code at the bottom to send an XML request and how to pull the information coming back.

The Example Code is the big commented section at the bottom of the SoapTools.asp.

You can ignore all the code above that, it will not need to change only included in your asp file.

http://www.vermeeralabama.com/SoapTools.asp

I hope this helps.
0
 
LVL 1

Expert Comment

by:stephenmmitchell
ID: 10786423
Sorry about that link, it was incorrect.  Try this one

http://www.vermeeralabama.com/SoapTools.txt

-Stephen
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11394724
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

"Accept rychs  comment as answer."

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Pinal Dave
EE Cleanup Volunteer
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question