1
votes

I need to call my .NET (C#) web service from a classic asp page. I want to test it by creating a console application that calls the asp page. This is my asp page:

Dim strUserID
Dim strUserName
Dim strUserEmail

strUserID = Request.Form("UserID")
strUserName = Request.Form("UserName")
strUserEmail = Request.Form("UserEMail")

SET objSoapClient = Server.CreateObject("MSSOAP.SoapClient")
objSoapClient.ClientProperty("ServerHTTPRequest") = True

Call objSoapClient.mssoapinit("http://localhost:/MyWebService/Service1/" & _
                                     "MyWebService.asmx?WSDL", "MyWebService")

strReturnValue = objSoapClient.SendData(strUserID, strUserName, strUserEmail)
response.Write("Returned from service with return value: " & strReturnValue)

Now my console application has to call the .asp page. How do I construct the URL? If the asp page is located in this folder: C:\Folder1\OldPage.asp, how do I construct the URL?

This is what I have so far:

static void Main(string[] args)
{
    WebClient client = new WebClient();      
    Uri aspPagingServiceUri = new Uri("http://localhost/Folder1/OldPage.asp?UserID=g39s24&UserName=Gloria [email protected]");
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPagingServiceUri);       
    httpWebRequest.Method = "GET";
    var response = httpWebRequest.GetResponse();
    HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
    Stream resStream = resp.GetResponseStream();

    StreamReader reader = new StreamReader(resStream);
    string strResponse = reader.ReadToEnd();
    Console.WriteLine(strResponse);

    reader.Close();
}

I get the error: 'The remote server returned an error: (503) Server Unavailable. ' when it gets to the GetResponse function.

I believe my problem is with the creation of the URL.

Thanks.

UPDATE I have trying to connect to the ASP file that on the web server. I am getting a (500) error: "The remote server returned an error: (500) Internal Server Error." The file is folder: C:\inetpub/wwwroot/Apps/Services/ServiceNew.asp This is my console application:

static void Main(string[] args)
{
    try
    {
        WebClient client = new WebClient();
        Uri aspPagingServiceUri = new Uri("http://myserverName/Apps/Services/ServiceNew.asp?UserID=g39r345&UserName=John Smith&[email protected]&Subject=Test&MSG=Testing&ContactList=Sam Smith;");
        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPagingServiceUri);
        httpWebRequest.Method = "GET";
        var response = httpWebRequest.GetResponse();
        HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
        Stream resStream = resp.GetResponseStream();

        StreamReader reader = new StreamReader(resStream);
        string strResponse = reader.ReadToEnd();
        Console.WriteLine(strResponse);

        reader.Close();
    }
    catch (WebException wex)
    {
        Console.WriteLine("Web Exception: " + wex.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("General Exception: " + ex.Message);
    }
}

The error is occurring var response = httpWebRequest.GetResponse();

Am I creating the URL correctly?
I am just following the file path.

1
I am calling a classic ASP file to run. I don't know if it has special libraries, components to add.Gloria Santin
Apologies - I'll remove that.Paul

1 Answers

2
votes

You can not execute ASP code directly. What you need is to setup a web server that can execute classic ASP, i.e. Internet Information Services (IIS) on your machine, on another computer in a local network or externally.

IIS is part of some Windows distributions, you may just have to activate it. Make sure to install the classic ASP module, as this is not installed by default nowadays.

A warning: classic ASP often depends on additional COM components. So you may have to install more to get your code working.