Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have asp ( classic ) application

what i need to do is..

i have to develop web service ( asmx ) to perform some functionality using Asp.net (4.0 or 3.5 )


can i call this web service in Asp( classic ) application ?

if yes then how ?

Appreciate your valuable response..

thanks
Posted
Updated 21-Feb-17 10:57am

Yes you can do that. CodeProject has an article which explains how to do it - Calling a WebService from ASP3.0 and JavaScript[^].

For more readings - Google Search - asp.net web service from classic asp[^]

Hope that helps!
 
Share this answer
 
You can do it directly in VB script also.
Use Below,
Step 1 - Created a simple ASP.Net ASMX service

C#
namespace TestService
{
using System;
using System.Web.Services;

    /// <summary>
    /// Summary description for MyService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class MyService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }        

        [WebMethod]
        public string[] PostData(Param param)
        {
            return new string[] { "value1", "value2", param.ParamId, param.ParamName };
        }
  }
   [Serializable]
    public class Param
    {
        public string ParamId { get; set; }
        public string ParamName { get; set; }
    }
}



HTML
<!--#include file="common.asp"-->
<body>
    <%  
     
        Dim str :  str = GetWSData("http://localhost/TestService/MyService.asmx", "HelloWorld", "")        
        
        Dim PostData : PostData = "<param><ParamId>value3</ParamId><ParamName>Value4</ParamName></param>"             
        Dim str1 : str1 = GetWSData("http://localhost/TestService/MyService.asmx", "PostData", PostData)                    
    %>
    <div>Hellow friends Time is now <%	=Time%>	</div>
    <div>My Name is <%=name %>11</div>
    <div>
        <![CDATA[ Some data here ]]>
        GET Response is  <%= str %>
        <br />
        POST Response is <%= str1 %>
    </div>
    
</body>



'''******* In Common.asp *****

Dim svcURI : svcURI = "http://tempuri.org/"

Function GetRequestBody(strMethodName, strPostData)
    Dim postContainer : postContainer = "<" & strMethodName & " xmlns=""" & svcURI & """>"
    postContainer = postContainer & strPostData & "</" & strMethodName & ">"
    GetRequestBody = postContainer
End Function 

function GetSoapEnvelope(xmlStr)    
    Dim soapEnvelope 
    soapEnvelope = "<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
    soapEnvelope = soapEnvelope & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> "
    soapEnvelope = soapEnvelope & "<soap:Body>"
    soapEnvelope = soapEnvelope & xmlStr & "</soap:Body></soap:Envelope>"
    GetSoapEnvelope = soapEnvelope
 end function	


 Function GetWSData(svcUrl, strMethodName, paramData)
    Dim resBody,reqBody     
    reqBody = GetRequestBody(strMethodName, paramData)  
    reqBody = GetSoapEnvelope(reqBody)
    resBody = CallWSMethod("POST",svcUrl,strMethodName, reqBody)    
    GetWSData = resBody'GetResultData(resBody, strMethodName)
 End function 

function CallWSMethod(strMethod, svcUrl, methodName, requestBody)
    Dim strUsername : strUsername = ""
    Dim strPasssword : strPasssword = ""
    Dim IsAsync : IsAsync = false
    Dim serviceResponse : serviceResponse = ""
    Dim objHttp
       
    'Set and Instantiate our working objects
    Set objHttp = Server.CreateObject("MSXML2.XMLHTTP")
    With objHttp 
        '.open strMethod, svcUrl, IsAsync, strUsername, strPasssword
        .open strMethod, svcUrl, IsAsync
        .setRequestHeader "Content-Type", "text/xml; charset=utf-8"    
        .setRequestHeader "SOAPAction", svcURI & methodName
        .send(requestBody)              
    End With     
    serviceResponse = objHttp.ResponseText
    
    set objHttp = Nothing
    CallWSMethod = serviceResponse
 End function
 
Share this answer
 
v5
Comments
Patrice T 21-Feb-17 17:08pm    
3 tears too late

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900