473,320 Members | 1,853 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.

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 6703
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: 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...
0
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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....

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.