Consuming Web Service using classis ASP

M

Mo

Hi,

I can not find a decent example showing how to consume a asp.net 2.0
web service using classic ASP. Does any body have an example I could
use?

Thanks
 
M

Mo

Thank you all for your great posts. I have created a simple helloworld
service which I am trying to call from ASP. I am using the following
code which is posted in one of the sites I found.:

html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim xmlhttp
Dim DataToSend
DataToSend="param1="&Request.Form("text1")
Dim postUrl
postUrl = " http://xxxlon.xxxmo.com/AWS.asmx/TestService HTTP/1.1"
Set xmlhttp = server.Createobject("MSXML2.XMLHTTP")
xmlhttp.Open "POST",postUrl,false
xmlhttp.setRequestHeader "Content-Type", _
"application/x-www-form- urlencoded"
xmlhttp.send DataToSend
Response.Write(xmlhttp.responseText)
End If
%>
<FORM method=POST name="form1">
Enter the two Values to be Added<BR>
<INPUT type="text" name="text1">

<BR><BR>
<INPUT type="submit" value="Add" name="submit1">
</form>
</body>
</html></PRE>

But when I access the page I am getting the following error:


Request format is unrecognized for URL unexpectedly ending in '/
TestService'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Request format is
unrecognized for URL unexpectedly ending in '/TestService'.


If I remove the /TestService from the service url I get the following
error after I submit the form:

soap:ReceiverSystem.Web.Services.Protocols.SoapException: Server was
unable to process request. ---> System.Xml.XmlException: Data at the
root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at
System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
at System.Xml.XmlReader.MoveToContent()
at
System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
at
System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at
System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at
System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage
message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type
type, HttpContext context, HttpRequest request, HttpResponse response,
Boolean& abortProcessing)
--- End of inner exception stack trace ---


What am I doing wrong?

Thanks
 
M

Mo

Thank you for all your great posts. I am still haven't been able to
get it to work. After I change the object to MSXML2.ServerXMLHTTP I
am getting 500 error on the browser after the button click. I also
tried removeing http/1.1 from the desciprion of the service and I get
the error saying that unexpected ending in /TestService.

Any other recommendations? There must be a working code somewhere. I
do not believe I am the first guy looking for this.

Thanks
 
D

Dave Anderson

Adeel Taseer said:
I am getting the same problem.

Same problem as what?

A web service can be accessed if both web service and ASP page are
on the same server, but if we change it to different servers then
it's not returning any response XML.

Are there any IP restrictions on the service you are attempting to consume?
What kind of response do you get if you consume the service directly with a
web browser (while logged onto the server that consumes the service) ?

Is the service on the remote server an ASP.NET Web Service? If so, have you
tried toggling this?
http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptserviceattribute.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top