从控制台应用程序调用经典 asp 页面
call a classic asp page from a console application
我需要从经典 asp 页面调用我的 .NET (C#) Web 服务。我想通过创建一个调用 asp 页面的控制台应用程序来测试它。
这是我的 asp 页面:
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)
现在我的控制台应用程序必须调用 .asp 页面。
如何构建 URL?
如果 asp 页面位于此文件夹中:C:\Folder1\OldPage.asp,如何构造 URL?
这是我目前拥有的:
static void Main(string[] args)
{
WebClient client = new WebClient();
Uri aspPagingServiceUri = new Uri("http://localhost/Folder1/OldPage.asp?UserID=g39s24&UserName=Gloria Test$UserEmail=gtest@hvhs.org");
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();
}
我得到错误:'The remote server returned an error: (503) Server Unavailable. ' 当它到达 GetResponse
函数时。
我认为我的问题在于创建 URL。
谢谢。
更新
我试图连接到网络服务器上的 ASP 文件。我收到 (500) 错误:"The remote server returned an error: (500) Internal Server Error."
该文件是文件夹:C:\inetpub/wwwroot/Apps/Services/ServiceNew.asp
这是我的控制台应用程序:
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&UserEmail=jsmith@mydomain.com&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);
}
}
发生错误var response = httpWebRequest.GetResponse();
我创建 URL 是否正确?
我只是按照文件路径。
您不能直接执行 ASP 代码。您需要的是设置一个可以执行经典 ASP 的 Web 服务器,即在您的计算机、本地网络中的另一台计算机或外部计算机上的 Internet 信息服务 (IIS)。
IIS 是某些 Windows 发行版的一部分,您可能只需要激活它。确保安装经典的 ASP 模块,因为现在默认情况下不安装它。
警告:经典 ASP 通常依赖于额外的 COM 组件。因此,您可能需要安装更多才能使您的代码正常工作。
我需要从经典 asp 页面调用我的 .NET (C#) Web 服务。我想通过创建一个调用 asp 页面的控制台应用程序来测试它。 这是我的 asp 页面:
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)
现在我的控制台应用程序必须调用 .asp 页面。 如何构建 URL? 如果 asp 页面位于此文件夹中:C:\Folder1\OldPage.asp,如何构造 URL?
这是我目前拥有的:
static void Main(string[] args)
{
WebClient client = new WebClient();
Uri aspPagingServiceUri = new Uri("http://localhost/Folder1/OldPage.asp?UserID=g39s24&UserName=Gloria Test$UserEmail=gtest@hvhs.org");
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();
}
我得到错误:'The remote server returned an error: (503) Server Unavailable. ' 当它到达 GetResponse
函数时。
我认为我的问题在于创建 URL。
谢谢。
更新 我试图连接到网络服务器上的 ASP 文件。我收到 (500) 错误:"The remote server returned an error: (500) Internal Server Error." 该文件是文件夹:C:\inetpub/wwwroot/Apps/Services/ServiceNew.asp 这是我的控制台应用程序:
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&UserEmail=jsmith@mydomain.com&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);
}
}
发生错误var response = httpWebRequest.GetResponse();
我创建 URL 是否正确?
我只是按照文件路径。
您不能直接执行 ASP 代码。您需要的是设置一个可以执行经典 ASP 的 Web 服务器,即在您的计算机、本地网络中的另一台计算机或外部计算机上的 Internet 信息服务 (IIS)。
IIS 是某些 Windows 发行版的一部分,您可能只需要激活它。确保安装经典的 ASP 模块,因为现在默认情况下不安装它。
警告:经典 ASP 通常依赖于额外的 COM 组件。因此,您可能需要安装更多才能使您的代码正常工作。