How to have an ASP page use a web service?

S

serge

Hello,

I have created a web service that will return SQL Server's Northwind
productid quantity.

If i access my web service from the Internet, i type the following:

http://www.mydomainnametest.com/northwind2/inventory.asmx

then i click on one of the web services there, for example GetInventory

http://www.mydomainnametest.com/northwind2/inventory.asmx?op=GetInventory

i get a text field where i enter the ProductID, press a command button and i
get the quantity of that ProductID.


Now, if i type the following at the address link :

http://www.mydomainnametest.com/northwind2/inventory.asmx?op=GetInventory?ProductID=2

i get the result also.

Now, my problem is I don't know how i can call this web service using an ASP
page. My goal is to use
another website to send a parameter to this web service and get the result
back, display the result on the html page for
the user and also insert the value in a SQL Server table.

Can someone please help me out? I need a sample code on how to write ASP
code to pass a value to a web
service residing on another server, get the result and display it on the
HTML page.


I would appreciate any help.

Thank you
 
S

serge

Thanks Aaron, that helped a lot.

This is the code of my test.asp located on my Inetpub/wwwroot folder

<%
url =
"http://www.mydomaintest.com/northwind2/inventory.asmx/GetInventory?producti
d=24"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
on error resume next
xmlhttp.open "GET", url, false
xmlhttp.send ""
if err.number <> 0 then
response.write "Url not found"
else
response.write xmlhttp.responseText
end if
set xmlhttp = nothing
%>

When i run http://localhost/test.asp

this is the result i get

<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://www.mydomaintest.com/Northwind2/Service1">61</int>


I I don't understand why sometimes when i run the same page after saving the
test.asp page
or deleting cookies, closing browser, doing all kinds of things... no idea
what i do/change, but
i get the result:

61

Only 61 gets printed on the page, but sometimes the same page no longer
prints 61, it prints the whole XML text again!


So, how i can simply retrieve only the value 61 and put it in a variable
and then print only the value of
the variable, instead of the whole XML string?

Anyone?

Thank you
 
A

Aaron Bertrand - MVP

You'd have to parse it, probably using RegExp would be your best bet.

(Chris Hohmann is the resident RegExpert around here...)
 
C

Chris Hohmann

Aaron Bertrand - MVP said:
"http://www.mydomaintest.com/northwind2/inventory.asmx/GetInventory?producti
You'd have to parse it, probably using RegExp would be your best bet.

(Chris Hohmann is the resident RegExpert around here...)

No need for RE's in this scenario. Use Response.ContentType to explicitly
declare the type of data being returned to the browser, i.e. XML, HTML,
plain text, etc... If that does not resolve the ambiguity, please post back
here.

-Chris Hohmann
P.S. "RegExpert"... lol! :)
 
S

serge

Actually, i added the line

Response.ContentType = "text/xml"
before the
Response.Write xmlhttp.responseText

However, i don't think i know what else to do.
How can i simply retrieve the value from this XML string :

<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://www.mydomaintest.com/Northwind2/Service1">61</int>

All i need is to put the value 61 in a variable in the ASP page.

Is the only way to get it is to read the whole string and disect the part
that interests me?

By the way, the whole ASP code here, does it have anything to do with SOAP?
If not, does using SOAP give me from freedom to access the result?


Thank you for your help Chris.
 
B

Bob Barrows [MVP]

serge said:
Actually, i added the line

Response.ContentType = "text/xml"
before the
Response.Write xmlhttp.responseText

However, i don't think i know what else to do.
How can i simply retrieve the value from this XML string :

<?xml version="1.0" encoding="utf-8" ?>
<int
xmlns="http://www.mydomaintest.com/Northwind2/Service1">61</int>

All i need is to put the value 61 in a variable in the ASP page.

Use an xml document.
After the Send statement:

Set xmldoc = xmlhttp.responseXML
thevalue = xmldoc.documentElement.text
response.write thevalue

Bob Barrows
 
S

serge

All i need is to put the value 61 in a variable in the ASP page.
Use an xml document.
After the Send statement:

Set xmldoc = xmlhttp.responseXML
thevalue = xmldoc.documentElement.text
response.write thevalue

Thank you Bob, that does what i wanted.

Now only if i can find a simple ASP example that executes SOAP Action.
 
A

Aaron Bertrand - MVP

Now only if i can find a simple ASP example that executes SOAP Action.

Why? The result is still going to be an XML string you'll have to parse,
and Bob already gave you code that does that?
 
S

serge

Yes, True Bob did give me the code i wanted.

But, i am somewhat confused about all this SOAP thing.

The web services i created in Visual .NET show me some code about SOAP
Action,
HTTP POST, GET etc...

So i am trying to try that SOAP ENVELOPE thing, see what is the difference.
Basically,
trying to learn, test and understand the differences.

If you happen to know a good book that explains SOAP and ASP or ASP.NET i
guess,
please let me know.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top