Using Web Service (.NET) in Classic ASP via SOAP

Web services are a great tool to share data across many data sources within a single organization, even if the owners of the different sources don’t want to give others direct access to the data.
here I am showing how you can call web service in classic asp.
To start, create a Web Service in Visual Studio.NET or use existing web service.
here is my web service login.asmx coding file (login.cs),

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
///
/// Summary description for Login
/// <code>
[WebService(Namespace = "http://ashishblog.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[ScriptService]
public class Login : System.Web.Services.WebService {
[WebMethod]
public int LoginValidate(string email, string PW)
{
bool OK = false; 

// validate email or pW
if(email =="[email protected]" && PW=="ashish")
{
OK = true;
}
return OK;
}
}


To fatch data or access Web Service via SOAP, you need to download SOAP 3.0 in your sever or local computer where you host asp page.
Here is classic asp coding (Default.asp)

<%@ LANGUAGE="VBSCRIPT" %>

<%  Option Explicit %>

<%

Public Function IsValidUser(Email, Pass)

Dim objSoapClient

SET objSoapClient = Server.CreateObject("MSSOAP.SoapClient30")

objSoapClient.ClientProperty("ServerHTTPRequest") = True

' needs to be updated with the url of your Web Service WSDL and is

' followed by the Web Service name

Call objSoapClient.mssoapinit("http://ashishblog/login.asmx?WSDL", "Login")

' use the SOAP object to call the Web Method Required

IsValidUser = objSoapClient.LoginValidate(Email, Pass)

End Function

%>

<%

Dim submitted, password, email

submitted = request.form("submitted")

if submitted <> "" then

submitted = true

email = request.form("email")

password = request.form("password")

Dim valid

valid = IsValidUser(email,password)

Response.Write valid

End If

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

<style type="text/css">

#submit2

{width: 96px;}

</style>

</head>

<body>

<form action="Default.asp?a=1"  method="post" name="memberLogin" AUTOCOMPLETE="off">

<%If request.queryString("a") <> 1 then%>

<table width="300" border="0" cellpadding="3" cellspacing="0">

<tr><td>

<table cellspacing="1" cellpadding="3">

<tr><td class="r3">Email Address: </td>

<td class="r2"><input name="email" type="text" size="50" maxlength="128" style="width: 246px" /></td>

</tr><tr>

<td class="r3">Password:</td>

<td class="r2"><input name="password" type="password" size="50" maxlength="15" style="width: 246px" /></td>

</tr><tr>

<td colspan="2" class="r2" align="right"><input type="hidden" name="submitted" value="true" />

<input name="submit" type="submit" id="submit2" alt="Login" align="bottom" />

</td></tr>

</table></td></tr>

</table>

<%End If %>

</form></body></html>

Here is design mode of Default.asp page


Thanks

One response to “Using Web Service (.NET) in Classic ASP via SOAP”

  1. how to pass xml as argument
    i need some help….
    my project is like that…
    UI is generate file.xml its pass as a parameter to .dll file (ui n .dll on same machine)..
    now this .dll retun a xml file which is pass as a parameter to ws…
    my problem is-> how to pass xml as a parameter to ws???

Leave a Reply