I played around with the listfiles example in the Vault sdk and struggled, like a lot of others i think. With getting the windows login to work. i made it at an inventor addin and here is what worked for me. but how do i ensure a proper logout? any help appreciated
regards.
kent boettger
Private Const HOST As String = "srv-pdm" '"localhost" Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click 'RunCommandNormalLogin(HOST) RunCommandWinLogin(HOST) End Sub Public Sub RunCommandWinLogin(ByVal serverName As String) 'Login with Windows User login Dim winAuthSvc As WinAuthService = New WinAuthService() winAuthSvc.Url = "http://" + serverName + "/AutodeskDM/Services/WinAuth/WinAuthService.asmx" winAuthSvc.UseDefaultCredentials = True winAuthSvc.SecurityHeaderValue = New WinAuthSvc.SecurityHeader() winAuthSvc.SignIn("Vault") Dim docSrv As DocumentService = New DocumentService() docSrv.SecurityHeaderValue = New Autodesk.Connectivity.WebServices.DocumentSvc.SecurityHeader() docSrv.SecurityHeaderValue.UserId = WinAuthSvc.SecurityHeaderValue.UserId docSrv.SecurityHeaderValue.Ticket = WinAuthSvc.SecurityHeaderValue.Ticket docSrv.Url = "http://" + serverName + "/AutodeskDM/Services/DocumentService.asmx" Dim login As WinAuthCredentials = New WinAuthCredentials(serverName, "Vault") Using serviceManager As New WebServiceManager(login) Try Dim root As Folder = docSrv.GetFolderRoot() Me.m_listBox.Items.Clear() PrintFilesInFolder(root, docSrv) Catch ex As Exception MessageBox.Show(ex.ToString(), "Error") End Try End Using End Sub
Solved! Go to Solution.
Solved by Daniel.Dulzo. Go to Solution.
The WebServiceManager will log out for you when the USING block exists. This article explains things more.
I apologize. The VB version of VaultList could have been written better. In fact, you can remove about half the code in your RunCommandWinLogin. Everything before "Dim login as WinAuthCredentials" can be removed.
For the next SDK release, we cleaned it up a bit to look like this...
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
ListAllFiles()
End Sub
''' <summary>
''' This function lists all the files in the Vault and displays them in the form's ListBox.
''' </summary>
Public Sub ListAllFiles()
' Set up the login credentials for Vault.
' For demonstration purposes, the information is hard-coded.
Dim login As New UserPasswordCredentials("localhost", "Vault", "Administrator", "", _
True) ' log in as read-only, which doesn't consume a license
' Create the WebServiceManager which can be used for all Vault Server calls.
' Putting the manager in a using block insures that it logs out when we are done.
Using serviceManager As New WebServiceManager(login)
Try
' Start at the root Folder.
Dim root As Folder = serviceManager.DocumentService.GetFolderRoot()
Me.m_listBox.Items.Clear()
' Call a function which prints all files in a Folder and sub-Folders.
PrintFilesInFolder(root, serviceManager)
Catch ex As Exception
MessageBox.Show(ex.ToString(), "Error")
Return
End Try
End Using
End Sub
Hi Doug,
I'm trying to search through these forums for problems similar to mine and found this one. Do the changes you made to Kent's original code still use the Windows login credentials? What about the Windows Authorization Service? Does it not get used anymore? You commented that you hard-coded for demonstration purposes, but now I'm really confused. Does your solution maintain the original login intent?
Larry Daubenspeck
Hi Larry,
Doug's code above doesn't use windows authentication, but demonstrates how to use the WebServiceManager to manage logging in and out of a Vault for you. The WinAuthService is still used, but if you use the WebServiceManager, it handles everything for you. You can give the WebServiceManager different types of credentials in its constructor if you would to authenticate in different ways. If you're trying to log in to a vault using windows authentication, you should construct the WebServiceManager using the WinAuthCredentials class. An example of its usage can be seen below:
using(WebServiceManager wsManager = new WebServiceManager(new WinAuthCredentials("localhost", "Vault"))
{
// use the wsManager here to make sever calls to vault
...
}
For more information, I recommend consulting the article that Doug points out in his post above.
Maybe a bit offtopic, but what about PowerShell? The hardcoded variant is:
Add-Type -Path "C:\Program Files (x86)\Autodesk\Autodesk Vault 2012 SDK\bin\Autodesk.Connectivity.WebServicesTools.dll" $cred = New-Object Autodesk.Connectivity.WebServicesTools.UserPasswordCredentials ("<TODOservername>","<TODOdatabase>","<TODOaccount>","<TODOpassword>",$true)
$webSvc = New-Object Autodesk.Connectivity.WebServicesTools.WebServiceManager ($cred)
Could you plese help to modfy it to WinAuth variant?
If you can't use a USING block, you can call Dispose() when you are done with the WebServiceManager. The Dispose will take care of the logout.
Example: $webSvc.Dispose()
Can't find what you're looking for? Ask the community or share your knowledge.