|
Home > Archive > IIS ASP > May 2004 > How to have an ASP page use a web service?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
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/nor.../inventory.asmx
then i click on one of the web services there, for example GetInventory
http://www.mydomainnametest.com/nor...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/nor...ory?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
| |
| Aaron Bertrand - MVP 2004-05-24, 4:33 pm |
| http://www.aspfaq.com/2173
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"serge" <sergea@nospam.ehmail.com> wrote in message
news:Nuqsc.16508$sr3.315197@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/nor.../inventory.asmx
>
> then i click on one of the web services there, for example GetInventory
>
> http://www.mydomainnametest.com/nor...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/nor...ory?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
>
>
| |
|
| 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
| |
| Aaron Bertrand - MVP 2004-05-24, 4:33 pm |
| 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" <sergea@nospam.ehmail.com> wrote in message
news:Bcssc.21032$tb4.630871@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
>
>
>
| |
| Chris Hohmann 2004-05-24, 11:32 pm |
| "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
news:eWImancQEHA.2704@TK2MSFTNGP10.phx.gbl...
> "serge" <sergea@nospam.ehmail.com> wrote in message
> news:Bcssc.21032$tb4.630871@news20.bellglobal.com...
>
"http://www.mydomaintest.com/northwind2/inventory.asmx/GetInventory?producti
> the
> idea
longer[vbcol=seagreen]
variable[vbcol=seagreen]
> 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! 
| |
| serge 2004-05-24, 11:32 pm |
| 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.
| |
| Bob Barrows [MVP] 2004-05-25, 7:33 am |
| 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"
| |
| serge 2004-05-25, 11:35 pm |
| > > 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.
| |
| Aaron Bertrand - MVP 2004-05-30, 11:53 am |
| > 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?
| |
| serge 2004-05-30, 11:53 am |
| 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" <aaron@TRASHaspfaq.com> wrote in message
news:eVsDCYyQEHA.2876@TK2MSFTNGP09.phx.gbl...
>
> 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?
>
>
|
|
|
|
|