DirectoryEntry de = new DirectoryEntry(@"IIS://" + this.MachineName + @"/W3SVC", this.LoginAccount, this.LoginPassword);当this.MachineName为本机即localhost的时候能够正常连接。当this.MachineName为远程机器的IP时,若账号密码错误,就报:拒绝访问。这个没问题。但是当账号密码正确的时候,就报:RPC 服务器不可用。有没有哪位大神碰到过并解决过这个问题的啊?PS:远程机器的RPC服务已开启小弟在此先谢过各位了!
看看远程的这个协议有没有
{
string MachineName = "127.0.0.1"; string LoginAccount = "username"; string LoginPassword = "password"; DirectoryEntry rootDirectory = new DirectoryEntry(@"IIS://" + MachineName + @"/W3SVC", LoginAccount, LoginPassword);
int totalServerCount = 0;
try
{ foreach (DirectoryEntry child in rootDirectory.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
totalServerCount++;
}
}
}
catch (Exception ex)
{
throw (new Exception("Can't connect to IIS Server " + MachineName + " : " + ex.Message));
} Console.WriteLine(totalServerCount);这是一段控制台测试程序,放入Program.cs的main方法中即可,需要引入System.DirectoryServices;