Using CUPI in a .NET environment

Version 1
    This document was generated from CDN thread

    Created by: John Farley on 19-08-2010 08:21:20 PM
    Does anyone have experience with or information about using CUPI in a .NET environment? 
     
    I know AXL for CUCM requires a proxy class to work in .NET.
     
    Most helpful would be an example of connecting to CUPI and performing basic operations in C#.NET.
     
    Thanks,
    John

    Subject: RE: Using CUPI in a .NET environment
    Replied by: Matthew Penning on 19-08-2010 08:21:20 PM
    Hi John - I don't have a C# example using CUPI specifically, but there's a couple of basic examples of making general REST request here:
     
    http://rest.elkstein.org/2008/02/using-rest-in-c-sharp.html
     
    Also I can tell you that you don't need a proxy class - this are  just plain old HTTP requests.
     
    - Matt

    Subject: RE: Using CUPI in a .NET environment
    Replied by: John Farley on 19-08-2010 08:21:20 PM
    Thanks, Matt
     
    I was able to get the GET method to return all CUC users using C#.NET and following the examples you posted.  I just had to add credentials and invoke ServerCertificateValidationCallback to get around validation of the local cert on the CUC box.
     
    But when I try to add or update a user following the examples in the wiki on this site, CUPI returns "<405> Method Not Allowed".  "Protocol Error".  I tried confirming the method and parameter names in the WADL, and both seem to match up.  I tried calling the CUPI methods using both HttpWebRequest and WebClient classes in C#.NET with no success.
     
    Any ideas?
     
    John

    Subject: RE: Using CUPI in a .NET environment
    Replied by: Matthew Penning on 19-08-2010 08:21:20 PM
    Hi John - one of the more subtle things in REST is that the content type is very important. If you aren't already, try setting the "Content-Type" header to "application/xml" when you post the user XML.
     
    - Matt

    Subject: RE: Using CUPI in a .NET environment
    Replied by: John Farley on 19-08-2010 08:21:20 PM
    Thanks, Matt.
     
    I got it working by forcing basic authentication in the message header as follows:
     
    byte[] authorizationHeaderBytes = System.Text.Encoding.UTF8.GetBytes("<user>" + ":" + "<password>");
    string authHeader = "Basic " + Convert.ToBase64String(authorizationHeaderBytes);
    client.Headers.Add("Authorization", authHeader);
     
    The above code replaces the previous authentication line:
    client.Credentials = new System.Net.NetworkCredential("<user>", "<password>");
     
    The next challenge is to enable and add an address to the SMTP notificaiton device type for each user.  Users created with CUPI in my testing have an SMTP notification type already that is disabled.  Maybe this comes from the template?
     
    Could you post an example of updating a user's SMTP notification device to set "Active" to true and write to the "SmtpAddress" value?
     
    John

    Subject: RE: Using CUPI in a .NET environment
    Replied by: John Farley on 19-08-2010 08:21:20 PM
    I got it:
     
    client.UploadString("https://<connection-server>/vmrest/users/<SubscriberObjectId>/notificationdevices/smtpdevices/<ObjectId>", "PUT", "<SmtpDevice><Active>true</Active><SmtpAddress>alias@domain.com</SmtpAddress></SmtpDevice>");
     
    I just have to query for the newly created user to get the <ObjectId> of the SMTP Device before calling the above method.
     
    John