我需要從經典的asp頁面調用我的.NET(C#)web服務。我想通過創建一個調用asp頁面的控制檯應用程序來測試它。 這是我的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 [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();
}
我得到的錯誤:「遠程服務器返回錯誤:(503)服務器不可用。 '當它到達GetResponse
函數。
我相信我的問題是與URL的創建。
謝謝。
UPDATE 我試圖連接到Web服務器上的ASP文件。我收到(500)錯誤:「遠程服務器返回錯誤:(500)內部服務器錯誤。」 該文件夾是:C:\的Inetpub/wwwroot文件/應用程序/服務/ 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&[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);
}
}
錯誤發生var response = httpWebRequest.GetResponse();
我是否正確地創建網址是什麼?
我只是跟隨文件路徑。
我正在調用一個經典的ASP文件來運行。我不知道它是否有特殊的庫,要添加的組件。 –
道歉 - 我會刪除。 – Paul