Get WebServiceManager in a Vault Event handler

By Wayne Brill

It is not obvious how to get the WebServiceManager in a WebService extension event handler. One of the arguments passed into the event is named “sender” by default. (A Vault event handler will have a sender and event arguments). The sender argument is simple object but it can be cast it to IWebService. You can use IWebService to create WebServiceCredentials and this can be used to create new instance of WebServiceManager. Here is a C# example of an event handler that gets the WebServiceManager:

 

void UpdateItemLifecycleStateEvents_Pre_wb         (object sender,           UpdateItemLifeCycleStateCommandEventArgs e)    {        Autodesk.Connectivity.WebServicesTools.            WebServiceCredentials CurrentCredentials =                             new Autodesk.Connectivity.               WebServicesTools.WebServiceCredentials                                ((IWebService)sender);             Autodesk.Connectivity.WebServicesTools.            WebServiceManager ServiceManager =                        new Autodesk.Connectivity.              WebServicesTools.WebServiceManager                                 (CurrentCredentials);             MessageBox.Show("From Event");    }

 

Note: Some operations may not work correctly when it’s executed from event handler (i.e. modifying of mapped properties when file is already open in Inventor). For such cases the safer approach may be to schedule a job and perform operation later.


Comments

One response to “Get WebServiceManager in a Vault Event handler”

  1. [NullReferenceException: Object reference not set to an instance of an object.]
    Alinea.WebProever.BusinessLogic.Services.UserService.SynchronizeUser(UniLoginUser uniLoginUser) +813
    Alinea.WebProever.BusinessLogic.Services.UserService.OnSynchronizeUser(Object sender, EventArgs e) +109
    System.EventHandlerExtensions.InvokeEvent(EventHandler`1 eventHandler, Object sender, T args) +191
    Alinea.Core.UniLogin.UniLoginController.UpdateUniLoginData(UpdateType updateType) +706
    Alinea.WebProever.BusinessLogic.UI.Web.WebStudentPage.ProcessAuthentication() +15
    System.Web.UI.Control.OnInit(EventArgs e) +96
    System.Web.UI.Page.OnInit(EventArgs e) +15
    System.Web.UI.Control.InitRecursive(Control namingContainer) +459
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1931

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading