基礎連接已關閉:連接被意外關閉System.Net.WebClient基礎連接已關閉
我使用Web客戶端時收到錯誤消息。我已經用asp代碼測試過了,它運行得很好。但是當我嘗試運行exe版本的代碼時,它運行以下錯誤,並且我能夠從服務器訪問請求地址,並且它位於內部網絡中。
我的服務器設置: - 的Windows Server 2003 SP2 Entrerprise asp.net 2.0.50727 IIS V6.0
下面是一些代碼:
手動訪問
protected static String cross_server_req(String strContent, String strPage, String strPrivateKey)
{
try
{
WebClient wc = new WebClient();
String strURL = SERVICE_PATH + strPage + "?r=" + DES_.DESEncrypt(strContent);
byte[] responseArray = wc.DownloadData(strURL);
String strResData = Encoding.UTF8.GetString(responseArray);
if (Config.RecordWebService == "1")
{
String strLogContent = "Request:" + strContent + "\r\nResponse:" + strResData + "\r\nDateCreated:" + D_Time.DNow + "\r\n\r\n";
ServiceLog.Logger(strPage, strLogContent);
}
if (null != strResData && String.Empty != strResData)
{
return strResData.Trim();
}
}
catch (Exception ex)
{
ServiceLog.Logger("cross_server_req() Exception:" + ex.Message + "\r\n" + ex.StackTrace);
}
return null;
}
這裏是從日誌
cross_server_req() Exception:The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadData(Uri address)
at System.Net.WebClient.DownloadData(String address)
at Account.cross_server_request_curl(String strContent, String strPage, String strPrivateKey)
請讓我知道任何建議,幫助這個問題?我查看了該網站,並找不到解決方案。
使用wcf服務嗎? – 2013-03-27 11:29:52
我沒有使用wcf服務。 – Gary 2013-03-28 04:44:21