[英]Why can't I hit my WCF service from the outside of the machine, but I can locally?
[英]Why can't I hit this UNC path from my Windows Service?
我正在使用C#開發文件復制服務。 該服務在我可以訪問用戶空間的環境中運行良好; 但是,當我將其作為服務運行時,我開始遇到錯誤。
在這種情況下,有關訪問UNC共享的信息很多,但是在尋求似乎最有可能的解決方案之后,我仍然很簡短。
在我的“故障”環境中,該服務以“管理員”帳戶的身份運行,並且我采取了幾種方法。 兩者都使用映射的網絡驅動器和特定的UNC共享,並且在兩種情況下最終都具有相同的結果。
我的構造函數包含用於檢測文件是否存在的邏輯,因此它應該是該方程式中唯一相關的部分。
public FileMonitor(String TargetPath)
: base()
{
if (String.IsNullOrEmpty(TargetPath))
{
throw new ArgumentNullException("Cannot instantiate FilesystemMonitor. TargetPath was not provided or is null.");
}
else
{
this.FileCache = new Dictionary<string, DateTime>();
if (Directory.Exists(TargetPath))
{
this.TargetDirectory = new DirectoryInfo(TargetPath);
return;
}
else if (File.Exists(TargetPath))
{
this.TargetFile = new FileInfo(TargetPath);
return;
}
else
{
if (TargetPath.StartsWith("\\\\"))
{
FileInfo Finfo = new FileInfo(TargetPath);
UNCHandler.connectToRemote(Finfo.DirectoryName, "administrator", "password");
if (Directory.Exists(TargetPath))
{
this.TargetDirectory = new DirectoryInfo(TargetPath);
return;
}
else if (File.Exists(TargetPath))
{
this.TargetFile = new FileInfo(TargetPath);
return;
}
else
{
throw new InvalidOperationException("Cannot instantiate FileMonitor for file that does not exist at " + TargetPath + ".");
}
}
else
{
throw new InvalidOperationException("Cannot instantiate FileMonitor for file that does not exist at " + TargetPath + ".");
}
}
}
}
我上一條語句的唯一例外是可能有必要知道UNCHandler類的功能-但要平息這場風暴,這是從“ 找到這里”的答案中得到的確切答案。
需要明確的是,這里的問題是即使嘗試連接到遠程系統后,File.Exists和Directory.Exists檢查也會失敗。
我的錯誤日志讓我退回了以下內容; 'system | ReadConfiguration:無法實例化Z:處不存在的文件的FileMonitor。' -這實際上是我在上述構造函數中生成的異常。
我嘗試使用各種方法來達到我的“來源”。 包括使用UNC共享和映射的驅動器,僅使結果無差異。
我接受了一個答案建議,並運行了Microsoft的Process Monitor,試圖對此做進一步的研究,但還沒有在該場所找到任何對我有幫助的信息。 在我的過程中,我獲得了數十次成功,直到嘗試達到份額為止。在這一點上,唯一的指示性結果是針對CreateFile操作的“名稱未找到”,以及稍后針對“文件未鎖定的文件”。 CreateFileMapping”調用。
該進程以本地系統管理員帳戶的身份運行,在我的“用戶空間”中,我有一個映射的驅動器到我要訪問的相同位置,可以完全操作。
你遇到了什么錯誤? 您是否嘗試過運行ProcessMonitor( http://technet.microsoft.com/zh-cn/sysinternals/bb896645.aspx )以查看發生了什么情況? 您是否以該計算機的本地管理員身份運行? 該本地管理員帳戶實際上是否有權訪問所討論的共享? 您是否嘗試過使用psexec( http://technet.microsoft.com/zh-cn/sysinternals/bb897553.aspx )以該用戶身份運行命令外殼,並查看您是否實際上有權訪問該共享?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.