473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to have an ASP page use a web service?

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/nort...inventory.asmx

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

http://www.mydomainnametest.com/nort...p=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/nort...ry?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
Jul 19 '05 #1
9 1514
http://www.aspfaq.com/2173

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"serge" <se****@nospam.ehmail.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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/nort...inventory.asmx

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

http://www.mydomainnametest.com/nort...p=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/nort...ry?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

Jul 19 '05 #2
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

Jul 19 '05 #3
You'd have to parse it, probably using RegExp would be your best bet.

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

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"serge" <se****@nospam.ehmail.com> wrote in message
news:Bc********************@news20.bellglobal.com. ..
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

Jul 19 '05 #4
"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
"serge" <se****@nospam.ehmail.com> wrote in message
news:Bc********************@news20.bellglobal.com. ..
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

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

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

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


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! :)
Jul 19 '05 #5
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.

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.

Jul 19 '05 #6
serge wrote:
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

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #7
> > 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.

Jul 19 '05 #8
> 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?
Jul 19 '05 #9
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
"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
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?

Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mr. x | last post by:
Hello, I wrote a javascript, and when I open the html by the browser, I get the message : Error in page. It is about tousand lines, and I cannot figure out in a simple way, where is the...
3
by: Carl Johansen | last post by:
I'm not sure of the best way to do what I want. Users of my website want to run reports that take a long time to generate. This is what I would like to happen: 1. User requests aspx page 2....
2
by: JD | last post by:
Hello, I'm experiencing a problem that I'm hoping someone might be able to shed some light on. I have an ASP.NET page on a Windows 2000 machine that makes web service calls to a .NET web...
1
by: achoo | last post by:
Is it possible to extend a Web service proxy so that it understands an HTTP refresh page? Explanation: * The Web service proxy was autogenerated by Visual Studio .NET 2003 from the Web...
2
by: Mongkon | last post by:
I use Visual studio.net 2003 for develop a web application by communicate with Web service (it has been developed by Java) and I has added web reference but It can’t to and show error message...
1
by: automation | last post by:
There is a truncation error of my Web Application using PHP 5.04, MySQL 5.022, and HTML(IE 6.0) whereby the MySQL Result Set is being truncated on the HTML page, even though the CSS Div Page Height...
0
by: sandydon | last post by:
when am trying this in xsl page <xsl:variable name="myArray"><item>item1</item><item>item2</item></xsl:variable> <xsl:value-of select="$myArray/item"/> i got the following error HTTP...
0
by: j74 | last post by:
I was testing some concepts and I came across following scenarios where include file does not seem working. Is the test code issue or some ATG setting issue? Though DSP jsp include works but jhtml...
4
by: Toni | last post by:
Is there a recommended way for a .ASP page to call a .ASPX page? I've got a function in an ASPX page that I need to call from an ASP page. The web site is quite busy, so I'd be happy to find the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.