带有C#-InitiateFileTransferToGuest的VMware vCenter API失败

带有C#-InitiateFileTransferToGuest的VMware vCenter API失败,c#,api,vmware,C#,Api,Vmware,我正在尝试使用InitiateFileTransferToGuest方法将文件发送到VM。不幸的是,我被卡住了。以下是相关代码,其中VClient是已成功连接的VimClient: GuestOperationsManager VMOpsManager = new GuestOperationsManager(VClient, VClient.ServiceContent.GuestOperationsManager); GuestFileManager VMFileManager = new

我正在尝试使用InitiateFileTransferToGuest方法将文件发送到VM。不幸的是,我被卡住了。以下是相关代码,其中VClient是已成功连接的VimClient:

GuestOperationsManager VMOpsManager = new GuestOperationsManager(VClient, VClient.ServiceContent.GuestOperationsManager);
GuestFileManager VMFileManager = new GuestFileManager(VClient, VClient.ServiceContent.FileManager);
GuestAuthManager VMAuthManager = new GuestAuthManager(VClient, VClient.ServiceContent.AuthorizationManager);

NamePasswordAuthentication Auth = new NamePasswordAuthentication()
{
    Username = "username",
    Password = "password",
    InteractiveSession = false
};

VMAuthManager.ValidateCredentialsInGuest(CurrentVM.MoRef, Auth);

System.IO.FileInfo FileToTransfer = new System.IO.FileInfo("C:\\userlist.txt");
GuestFileAttributes GFA = new GuestFileAttributes()
{
    AccessTime = FileToTransfer.LastAccessTimeUtc,
    ModificationTime = FileToTransfer.LastWriteTimeUtc
};

string TransferOutput = VMFileManager.InitiateFileTransferToGuest(CurrentVM.MoRef, Auth, "C:\\userlist.txt", GFA, FileToTransfer.Length, false);   
第一个错误出现在访问ValidateCredentialsInGuest方法时。我得到这个信息:

VMware.Vim.dll中发生类型为“VMware.Vim.VimException”的未处理异常。其他信息:请求引用了意外或未知类型

如果删除该验证,则在尝试运行InitiateFileTransferToGuest时会出现相同的错误。老实说,我一直在浏览API文档、VMware论坛和许多地方的线程。我所看到的唯一一段代码是用Java和Perl编写的,但是API实现与C#略有不同。知道去哪里找吗?
谢谢大家!

我在测试和编造了一些东西之后才让它工作起来。我猜测了AuthManager和FileManager执行以下操作的可能性:

ManagedObjectReference MoRefFileManager = new ManagedObjectReference("guestOperationsFileManager");
GuestFileManager VMFileManager = new GuestFileManager(VClient, MoRefFileManager);
ManagedObjectReference MoRefAuthManager = new ManagedObjectReference("guestOperationsAuthManager");
GuestAuthManager VMAuthManager = new GuestAuthManager(VClient, MoRefAuthManager);

现在它工作了,我不知道怎么做。

谢谢!也为我工作。非常感谢先前对此的研究。