WebServiceManager

The service manager concept has been around for a while.  Almost every SDK and blog sample has one.  For Vault 2012, we decided to build it into the API.  It's a bit tricky to get used to at first.  But once you get the hang of it, you'll love it.

WebServiceManager features:

  • Login management – It will handle the login and logout for you so you don't have to.
  • Service creation – The WebServiceManager is a factory, so it will create all your services for you.  You don't have to worry about calling new, setting the URL or copying security headers.
  • Re-SignIn – If you run into error 300, which means your login has been invalidated, the WebServiceManager will automatically catch the error, sign-in again, re-run the command, and return the new result.  This feature is only available if you use a credentials class that supports sign in.

How to use
The WebServiceManager can be found in Autodesk.Connectivity.WebServicesTools.dll.  As the name implies, it contains tools to help you use the web services.  Currently, the WebServiceManager is the main component of the DLL.

To create a WebServiceManager, you need to provide it with credentials, which tells the manager how to log in and log out of Vault.  There are several credentials classes available, so you need to use the appropriate one.  It usually is based on the information you have available.  For example, if you have the username and password, you would use the UserPasswordCredentials.  If you are in a custom command, and a context is passed in, you can use the UserIdTicketCredentials.

NOTE:  There are some known issues with UserIdTicketCredentials and WebServiceCredentials, so read this article first before using.

Once you have created your WebServiceManager, you are ready to start making web service calls.  It has properties for each service and each service has its full set of functions.

To sign out, just let WebServiceManager go out of scope.  It's an IDisposable class, which means it does special things before it gets garbage collected.  So that's where all the sign out happens if a sign out is needed.  I recommend declaring the WebServiceManager in a using statement if possible.  That way you know when Dispose() will get called.  If it doesn't make sense to have a using statement, I recommend explicitly calling Dispose() when you are done with it.  In effect, the Dispose() replaces SignOut().

Since the WebServiceManager references every service, which in turn references every server function, the WebServiceManager is the web services API.  You can just use a single object to make every Vault server call.

Sample code:
Here is a comparison of the old way versus the new way with the WebServiceManager.


// THE OLD WAY – C#

SecurityService
secSrv = new SecurityService();
secSrv.SecurityHeaderValue = new Autodesk.Connectivity.WebServices.SecuritySvc.SecurityHeader();
secSrv.Url = "http://localhost/AutodeskDM/Services/SecurityService.asmx";
secSrv.SignInReadOnly("Administrator", "", "Vault");

DocumentService docSrv = new DocumentService();
docSrv.SecurityHeaderValue = new Autodesk.Connectivity.WebServices.DocumentSvc.SecurityHeader();
docSrv.SecurityHeaderValue.UserId = secSrv.SecurityHeaderValue.UserId;
docSrv.SecurityHeaderValue.Ticket = secSrv.SecurityHeaderValue.Ticket;
docSrv.Url = "http://localhost/AutodeskDM/Services/DocumentService.asmx";

Folder
root = docSrv.GetFolderRoot();

secSrv.SignOut();


// THE NEW WAY – C#

UserPasswordCredentials login = 
    new UserPasswordCredentials(
    "localhost", "Vault", "Administrator", "", true);

using (WebServiceManager serviceManager = 
    new WebServiceManager(login))
{
    Folder root = 
        serviceManager.DocumentService.GetFolderRoot();
}

 


' THE OLD WAY – VB.NET

Dim secSrv As SecurityService = New SecurityService()
secSrv.SecurityHeaderValue = New Autodesk.Connectivity.WebServices.SecuritySvc.SecurityHeader
secSrv.Url = "http://localhost/AutodeskDM/Services/SecurityService.asmx"

secSrv.SignInReadOnly("Administrator", "", "Vault")

Dim docSrv As DocumentService = New DocumentService()
docSrv.SecurityHeaderValue = New Autodesk.Connectivity.WebServices.DocumentSvc.SecurityHeader
docSrv.SecurityHeaderValue.UserId = secSrv.SecurityHeaderValue.UserId
docSrv.SecurityHeaderValue.Ticket = secSrv.SecurityHeaderValue.Ticket
docSrv.Url = "http://localhost/AutodeskDM/Services/DocumentService.asmx"

Dim root As Folder = docSrv.GetFolderRoot()

secSrv.SignOut()


' THE NEW WAY – VB.NET

dim login As UserPasswordCredentials = _
    New UserPasswordCredentials(serverName, _
    "Vault", "Administrator", "")

Using serviceManager As New WebServiceManager(login)
    Dim root As Folder = _
        
serviceManager.DocumentService.GetFolderRoot()
End Using


Comments

4 responses to “WebServiceManager”

  1. Is it possible to transfer files in binary mode when using the WebServiceManager?

  2. Yes, the service objects all use WSE 3.0. However, you still need to enable MTOM by having a “microsoft.web.services3” section in the applications .config file.
    The following article explains how to update the .config file and test to make sure that binary transfer is working:
    http://justonesandzeros.typepad.com/blog/2010/03/file-transfer-as-binary-data.html

  3. Does this sign in method consume a Vault license at logon?

  4. The WebServiceManager supports all types of Vault logins. The normal login will consume a license when the manager signs-in to the server, which is when new is called on WebServiceManager.
    If a read-only is used, as shown in my sample code, then WebServiceManager will not consume a license. The last parameter on the UserPasswordCredentials constructor tells if the login will be read-only or not.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading