473,651 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Nam espace:="http://tempuri.org/")> _
Public Class TextData
Inherits System.Web.Serv ices.WebService

<WebMethod(Desc ription:="Simpl e 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.createob ject("MSXML2.XM LHTTP")

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

Set objXMLDoc = Server.createob ject("MSXML2.DO MDocument")
objXmlDoc.async = false

If objXMLDoc.LoadX ml(objRequest.R esponseXml.Xml) Then
Set objXMLNode = objXMLDoc.Selec tSingleNode("Ge tNameResponse")

If Not objXMLNode Is Nothing then
strRet = objXMLNode.Node TypedValue
Response.Write( "Response: " & sRet)
End If
Else
strError = objXMLDoc.parse Error.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 6719
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******** ******@tk2msftn gp13.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(Nam espace:="http://tempuri.org/")> _
Public Class TextData
Inherits System.Web.Serv ices.WebService

<WebMethod(Desc ription:="Simpl e 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.createob ject("MSXML2.XM LHTTP")

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

Set objXMLDoc = Server.createob ject("MSXML2.DO MDocument")
objXmlDoc.async = false

If objXMLDoc.LoadX ml(objRequest.R esponseXml.Xml) Then
Set objXMLNode = objXMLDoc.Selec tSingleNode("Ge tNameResponse")

If Not objXMLNode Is Nothing then
strRet = objXMLNode.Node TypedValue
Response.Write( "Response: " & sRet)
End If
Else
strError = objXMLDoc.parse Error.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?n ame=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.createob ject("MSXML2.XM LHTTP")

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

Set objXMLDoc = Server.createob ject("MSXML2.DO MDocument")
objXmlDoc.async = false

Response.Write( objRequest.Resp onseXml)

'If objXmlDoc.LoadX ml(objRequest.R esponseXml.Xml) Then
' Set objXmlNode = objXmlDoc.Selec tSingleNode("Ge tNameResponse")
' If Not objXmlNode Is Nothing Then
' strRet = objXmlNode.Node Typedvalue
' Response.Write( strRet)
' End If
'Else
' strError = objXmlDoc.parse Error.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******@hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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?n ame=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.Selec tSingleNode("st ring")

Lastly, since you are not using SOAP, you can safely delete the setRequestHeade r "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.LoadX ml(objRequest.R esponseXml.Xml) Then
' Set objXmlNode = objXmlDoc.Selec tSingleNode("Ge tNameResponse")
' If Not objXmlNode Is Nothing Then
' strRet = objXmlNode.Node Typedvalue
' Response.Write( strRet)
' End If
'Else
' strError = objXmlDoc.parse Error.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
19155
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 Event log. My environment: Windows Server 2003, IIS 6, WSH, Classic ASP, Vbscript Below is the code and the error: Code:
4
613
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 service: <WebService(Namespace:="http://tempuri.org/")> _ Public Class TextData Inherits System.Web.Services.WebService
3
5250
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. I am trying to call this webservice via classic asp. This works as long as the service is not authenticated. Here is the asp code: ...
2
5291
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, by using the header of the soap request. How can I send this information to the webservice? Thanks in advance
1
2095
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 would appreciate any comments, particularly from somone who has done this before. Create a .net WS to expose the Com Objects >From searching the web it looks like a couple of options are available to access the web service from classic asp:
1
3148
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 Set oSoap = Server.CreateObject("MSSOAP.SoapClient30") oSoap.ClientProperty("ServerHTTPRequest") = True
0
1746
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 server , which is IIS6.0. On first calling the WebService the asp page either hangs or returns Active Server Pages error 'ASP 0113' Script timed out /adminw/logon/DeleteUser.asp
2
1854
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 number of parameters, process some logic,and then return some information to the consumer. I've now built a number of these services (Following something of a RESTful approach), and the next one I need to build happens to require some information...
2
2065
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 system.net.webexception return instead of the correct return. Would anyone have any advice or suggest any extra debugging I could do to find out where this problem might occur? The second problem I am having is: I also called some functions within the web...
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.