Link to home
Start Free TrialLog in
Avatar of mousemat24
mousemat24

asked on

Consume a Web service in classic ASP

Hi there

I have a web service in .NET, and I need a classic ASP file to consume it, I've got the following code:

<%
Response.Write consumeWebService("AMF")

Function consumeWebService(zip)
    Dim webServiceUrl, httpReq, node, myXmlDoc
   
    webServiceUrl = "http://test.com/eLearningService.asmx/GetSize?CC=" & zip

    Set httpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
response.write ("asd")    
    httpReq.Open "GET", webServiceUrl, False
response.write ("asd1")    
    httpReq.Send
response.write ("asd2")    
   
    Set myXmlDoc =Server.CreateObject("MSXML.DOMDocument")
    myXmlDoc.load(httpReq.responseBody)
   
    Set httpReq = Nothing
   
    Set node = myXmlDoc.documentElement.selectSingleNode("//GetDownloadSizeResult")
   
    If Not node Is Nothing Then
        consumeWebService = "<b>That zipcode is within this city:</b><font color = blue>" & node.text & "</font>"
        Exit Function
    Else
        consumeWebService = "<b>There is no location associated with that zipcode.</b>"
        Exit Function
    End If    
End Function


%>


And I never get pass response.write ("asd1")

Any idea why I cant see response.write ("asd2")?

Thanks
Avatar of vnvk
vnvk
Flag of United States of America image

r u able to connect to the webservice and get the content?

Also, check on what are the types of characters that ur webservice will accept? I feel that you are not getting authenticated, hence, not being able to go pass response.write("asd1")
Using webservices with parameters in the url is depicrated by microsoft. You can still use it, if you reconfigure the webservice to support it.

Try using

<%
Only to process a Post Request
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim oSOAP
    'Create an object of Soap Client
    Set oSOAP = Server.CreateObject("MSSOAP.SoapClient")
    oSOAP.ClientProperty("ServerHTTPRequest") = True
    'Initaialize the Web Service
    oSOAP.mssoapinit("http://localhost/Add/test.asmx?wsdl")
    'Invoke the Web Service
    Response.write(oSOAP.Add(Request.Form("text1"), _
                   Request.Form("text2")) & "<BR>")
End If
%>
Avatar of mousemat24
mousemat24

ASKER

bugs

my method name is called GetSize, and I need to pass a param to it called AMF

How can I get it to work with your example?

Do I need to place the wsdl at the end of the URL?


http://test.com/eLearningService.asmx/GetSize?CC=


Thanks
Sorry i made a typo. It should have been

oSOAP.mssoapinit("http://test.com/eLearningService.asmx/GetSize")

'Invoke the Web Service
    Response.write(oSOAP.Add(CC))
Here I will type the complete example

<html>
<head>
<title>CONSUME WEBSERVICE</title>
</head>
<body>
<%
Only to process a Post Request
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim oSOAP
    'Create an object of Soap Client
    Set oSOAP = Server.CreateObject("MSSOAP.SoapClient")
    oSOAP.ClientProperty("ServerHTTPRequest") = True
    'Initaialize the Web Service
    oSOAP.mssoapinit("http://test.com/eLearningService.asmx/GetSize")
    'Invoke the Web Service
    Response.write(oSOAP.Add(Request.Form("CC"))
End If
%>
<FORM method=POST name="form1">
.<BR>
<INPUT type="text" name="CC">
<BR><BR>
<INPUT type="submit" value="Add" name="submit1">
</form>
</body>
</html>
bugs

How do I pass a para to the WS, I'm really sorry about the 101 questions, but I've spent all day on this, and havent done anything

Thanks
I see you are passing AMF as the ZIP to your webservice.

In my example there is a textbox which sends the parameter.

For you, all you have do is

'Initaialize the Web Service
    oSOAP.mssoapinit("http://test.com/eLearningService.asmx/GetSize")
 'Invoke the Web Service
    Response.write(oSOAP.Add('AMF')               'Try either single or double quote

One more thing does your NODE in the webservice has /GetDownloadSizeResult
CAN YOU please paste the WEBSERVICE for us
bugs

When I click on the Submit button, it dosnt go to any page, I get
The page cannot be displayed


HTTP 500 - Internal server error
Internet Explorer
ASKER CERTIFIED SOLUTION
Avatar of bugs021997
bugs021997
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@mousemat24

If you still could not get me then maybe I am not explaining right. But still would try. Try checking the below link and it will help you

http://www.w3schools.com/webservices/ws_use.asp
It would be great if you paste your Webservice for me to understand.

Please check the NODES. ??? If the node is GetDownloadSizeResult
thanks for all your help bugs, its very kind of you!

This is my code

<html>
<head>
<title>CONSUME WEBSERVICE</title>
</head>
<body>

<script>
Function consumeWebService()
    Dim soapClient
    Set soapClient = Server.CreateObject("MSSOAP.SoapClient")
    soapClient.ClientProperty("ServerHTTPRequest") = True
    soapClient.mssoapinit "http://edeploy-ws.pwcinternal.com/eLearningService.asmx?wsdl
    consumeWebService = soapClient.GetDownloadSize("AMF")
alert(consumeWebService)
End Function
</script>
<FORM method=POST name="form1">
<BR>
<INPUT type="text" name="CC">
<BR><BR>
<INPUT type="button" onclick="consumeWebService()" value="Add" name="asdasd">
</form>
</body>
</html>
Hi,

By looking at www.xmethods.net, you can get a list of all the webservices that are registered.

For using webservices in ASP.NET , you can see this URL :

http://www.aspng.com/quickstart/aspplus/doc/servicesanddata.aspx

Hope that helps.

The simplest method that I have found to cunsume Webservice from ASP is by using Microsoft's WebService Behavior.

You can download it and find description from
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp.

This is description from MS:

The WebService behavior enables client-side script to invoke remote methods exposed by Web Services, or other Web servers, that support the SOAP and Web Services Description Language (WSDL) 1.1. This behavior provides developers the opportunity to use and leverage SOAP, without requiring expert knowledge of its implementation. The WebService behavior supports the use of a wide variety of data types, including intrinsic SOAP data types, arrays, objects, and Extensible Markup Language (XML) data. The WebService behavior is implemented with an HTML Component (HTC) file as an attached behavior, so it can be used in Microsoft® Internet Explorer 5 and later versions.
but it dosnt display the int that GetDownloadSize should display
here is my WS code


 public int GetDownloadSize(string CourseCode)
        {
            Course objCourse = Builder.GetCourse(CourseCode, true);


            return Builder.GetDownloadSize(CourseCode, objCourse.DownloadBuildNumber);
           
        }
Till then Try going through the links i have sent you last...
with your example

Response.Write consumeWebService()

Function consumeWebService()
    Dim soapClient
    Set soapClient = Server.CreateObject("MSSOAP.SoapClient")
    soapClient.ClientProperty("ServerHTTPRequest") = True
    soapClient.mssoapinit "http://test.com/eLearningService.asmx?wsdl
    consumeWebService = soapClient.GetSize("BUGS")
End Function



I get an error

Object required: Server

I beleive its on this line

Set soapClient = Server.CreateObject("MSSOAP.SoapClient")


Thanks
thanks for all your help, that worked :-)