473,399 Members | 2,774 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,399 software developers and data experts.

Calling a .NET web service from classic ASP

Hi.

I have a very simple web service that I am trying to call from a classic ASP
page. The web service project and the ASP page are both on my development
machine. That's the code of my web service:

<WebService(Namespace:="http://tempuri.org/")> _
Public Class TextData
Inherits System.Web.Services.WebService

<WebMethod(Description:="Simple method")> _
Public Function GetName(ByVal sName As String) As String
Return "The name is: " & sName
End Function

End Class

And in my ASP page I have the following code:

<%Option Explicit
Dim objRequest, objXMLDoc, objXmlNode, strRet, strError
Set objRequest = Server.createobject("MSXML2.XMLHTTP")

With objRequest
.open "GET", "HTTP://tempuri.org/TextData/TextData.asmx", False
.setRequestHeader "Content-Type", "text/xml"
.setRequestHeader "SOAPAction", "HTTP://tempuri.org/GetName"
.send
End With

Set objXMLDoc = Server.createobject("MSXML2.DOMDocument")
objXmlDoc.async = false

If objXMLDoc.LoadXml(objRequest.ResponseXml.Xml) Then
Set objXMLNode = objXMLDoc.SelectSingleNode("GetNameResponse")

If Not objXMLNode Is Nothing then
strRet = objXMLNode.NodeTypedValue
Response.Write("Response: " & sRet)
End If
Else
strError = objXMLDoc.parseError.reason
Response.Write("Error: " & strError)
End If

%>
When I run the ASP page, I receive the error: XML document must have a top
level element.

What do I need to do in order to consume this web service in a classic ASP
page? And why do I need to use tempuri.org instead of localhost, in my
Request?

Thank you,
Julian
Nov 18 '05 #1
4 6708
I'm not an expert on SOAP, in fact, I don't know much about it but it looks
like you're missing SOAP body.
You'll need SOAP body in the request body in addition to the SOAPAction in
the request header.

you don't have to use tempuri.org if you don't want to. You gave your
webservice the namespace tempuri.org. Change it to whatever you want and
make sure you match it in your request.

"Julian Hershel" <jh**************@exds.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...
Hi.

I have a very simple web service that I am trying to call from a classic ASP page. The web service project and the ASP page are both on my development
machine. That's the code of my web service:

<WebService(Namespace:="http://tempuri.org/")> _
Public Class TextData
Inherits System.Web.Services.WebService

<WebMethod(Description:="Simple method")> _
Public Function GetName(ByVal sName As String) As String
Return "The name is: " & sName
End Function

End Class

And in my ASP page I have the following code:

<%Option Explicit
Dim objRequest, objXMLDoc, objXmlNode, strRet, strError
Set objRequest = Server.createobject("MSXML2.XMLHTTP")

With objRequest
.open "GET", "HTTP://tempuri.org/TextData/TextData.asmx", False
.setRequestHeader "Content-Type", "text/xml"
.setRequestHeader "SOAPAction", "HTTP://tempuri.org/GetName"
.send
End With

Set objXMLDoc = Server.createobject("MSXML2.DOMDocument")
objXmlDoc.async = false

If objXMLDoc.LoadXml(objRequest.ResponseXml.Xml) Then
Set objXMLNode = objXMLDoc.SelectSingleNode("GetNameResponse")

If Not objXMLNode Is Nothing then
strRet = objXMLNode.NodeTypedValue
Response.Write("Response: " & sRet)
End If
Else
strError = objXMLDoc.parseError.reason
Response.Write("Error: " & strError)
End If

%>
When I run the ASP page, I receive the error: XML document must have a top
level element.

What do I need to do in order to consume this web service in a classic ASP
page? And why do I need to use tempuri.org instead of localhost, in my
Request?

Thank you,
Julian

Nov 18 '05 #2
Hello Julian,
What do I need to do in order to consume this web service in a classic
ASP page? And why do I need to use tempuri.org instead of localhost,
in my Request?


tempuri.org is actually the namespace that is used for the web service. Your problem arises from this line:

.open "GET", "http://tempuri.org/TextData/TextData.asmx", False

This line should actually read (assuming your webservice is hosted on the local machine):
.Open "GET", "http://localhost/TextData/TextData.asmx", False

Also, since your method is expecting a string you will want to pass this along on the querystring (ie: TextData.asmx?name=Foo or use a POST method to pass the parameter along.

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #3
Hi Matt.

I changed my ASP page as you told me and it worked, thanks. That's my final
code but I would like your help one more time:

<%Option Explicit
Dim objRequest, objXMLDoc, objXmlNode
Dim strRet, strError, strNome

strName = "Julian"
Set objRequest = Server.createobject("MSXML2.XMLHTTP")

With objRequest
.open "GET", "http://localhost/TextData/TextData.asmx/GetName?sName=" &
strName, False
.setRequestHeader "Content-Type", "text/xml"
.setRequestHeader "SOAPAction", "HTTP://localhost/TextData/GetName"
.send
End With

Set objXMLDoc = Server.createobject("MSXML2.DOMDocument")
objXmlDoc.async = false

Response.Write(objRequest.ResponseXml)

'If objXmlDoc.LoadXml(objRequest.ResponseXml.Xml) Then
' Set objXmlNode = objXmlDoc.SelectSingleNode("GetNameResponse")
' If Not objXmlNode Is Nothing Then
' strRet = objXmlNode.NodeTypedvalue
' Response.Write(strRet)
' End If
'Else
' strError = objXmlDoc.parseError.reason
' Response.write(strError)
'End If
%>

I see the entire response in xml. How can I extract only the sName parameter
from the returned xml? The commented code does not work :-(

Thanks,
Julian

"Matt Berther" <mb******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello Julian,
What do I need to do in order to consume this web service in a classic
ASP page? And why do I need to use tempuri.org instead of localhost,
in my Request?

tempuri.org is actually the namespace that is used for the web service.

Your problem arises from this line:
open "GET", "http://tempuri.org/TextData/TextData.asmx", False

This line should actually read (assuming your webservice is hosted on the local machine): Open "GET", "http://localhost/TextData/TextData.asmx", False

Also, since your method is expecting a string you will want to pass this along on the querystring (ie: TextData.asmx?name=Foo or use a POST method to
pass the parameter along.
--
Matt Berther
http://www.mattberther.com

Nov 18 '05 #4
Hello Julian,

First of all, if you're using .NET 1.1 and have not overridden machine.config to allow HTTP GET requests for your web service, you will need to enable that by adding the following XML to your web.config, under the system.web element:

<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
</webServices>

Secondly, since youre not using SOAP, you can expect this simple response to be in the format of:

<string xmlns="http://tempuri.org/">The name is: Julian</string>

Hence, you should be able to extract the data that you want with something like:

Set objXmlNode = objXmlDoc.SelectSingleNode("string")

Lastly, since you are not using SOAP, you can safely delete the setRequestHeader "SOAPAction" line.

I've re-created your simple webservice on my development machine here and it does work after making the changes I just detailed.

If you have further questions, please let me know.
'If objXmlDoc.LoadXml(objRequest.ResponseXml.Xml) Then
' Set objXmlNode = objXmlDoc.SelectSingleNode("GetNameResponse")
' If Not objXmlNode Is Nothing Then
' strRet = objXmlNode.NodeTypedvalue
' Response.Write(strRet)
' End If
'Else
' strError = objXmlDoc.parseError.reason
' Response.write(strError)
'End If
%>
I see the entire response in xml. How can I extract only the sName
parameter from the returned xml? The commented code does not work :-(


--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #5

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

Similar topics

3
by: Yitzhak | last post by:
I am having "Permission denied" error while calling LogEvent method of WScript.Shell component. Basically, ASP page calls Windows Script Host Shell component to log events to the OS Application...
4
by: Julian Hershel | last post by:
Hi. I have a very simple web service that I am trying to call from a classic ASP page. The web service project and the ASP page are both on my development machine. That's the code of my web...
3
by: ryan.mclean | last post by:
Hi everyone! I'm hoping that someone can help me out. I have a webservice written in vb.net. This service uses the SoapHeader to secure the webservice to users that give a username and password....
2
by: Filippo | last post by:
Hi, I have to call a .Net WebService from a non .net Webserver. So I create an asp page that use the Soap Toolkit for calling the Webserver. The problem is that the webservice use authentication,...
1
by: AnRonMor | last post by:
Currently I use the MS Soap Toolkit to expose some 20 or so com objects for use by classic asp pages, this has to be replaced as support is ending. I have found two proposed solutions below and...
1
by: ecydba | last post by:
When attempting to use a web service that has NTFS permissions to the Domain Users group and Anonymous access turned off in IIS on a WinXP machine with the following classic ASP code: Dim oSoap...
0
by: =?Utf-8?B?QWRhbUM=?= | last post by:
Hi, I'm wondering if you can help. We have a classic asp application that creates and posts some XML using the SOAP format to a .NET WebService. The WebService and the asp are on the same IIS...
2
by: brian.ackermann | last post by:
Hello All, I have a project where I am being asked to expose some functionality to a customer via a web-service-like interface. This service will be written in Classic ASP, and will take a...
2
by: =?Utf-8?B?SnVsaWFu?= | last post by:
My first problem is: I am having an issue when using a web service. The web service is written by another department and say its running fine but when I call it, I sometimes I get a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.