Results 1 to 7 of 7

Thread: Zimbra CSharp Client Library

  1. #1
    redcoatj is offline Starter Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    7

    Post Zimbra CSharp Client Library

    Hello,

    I am currently reviewing the ZimbraCSharpClient (SourceForge.net Repository - [zimbra] Index of /trunk/ZimbraCSharpClient) C# library. There is a namespace called, Zimbra.Client.Admin which has two concrete classes: AuthRequest and GetAccountRequest.

    Based on the design, I understand that each concrete class represents a service in the Zimbra Admin API (http://zimbra.svn.sourceforge.net/vi...t?revision=841) .

    I am considering to use this library as a means for a .NET application to send SOAP messages to Zimbra. Thus, I am working with the idea of expanding the Zimbra.Client.Admin namespace to implement portions of the API I plan to use.

    However, I have not been able to locate documentation regarding the Zimbra CSharp Client library and thus am not clear of the original intent. It seems perfectly logical to expand the library to create and delete accounts, but it may very well have been designed to authenticate and retrieve user information.

    I appreciate any advise or guidance. Thank you in advance.

  2. #2
    ronnyek is offline Senior Member
    Join Date
    Dec 2006
    Posts
    58
    Rep Power
    8

    Default

    I've begun to do this very thing... and what I've found is that it would seem the library was intended to do some very basic auth and checking folders, deleting messages etc.

    I've been able to successfully add creating domains/accounts deleting domains and accounts, reindexing mailboxes, change passwords etc

    Its a shame zimbra chose a somewhat arsed implementation of soap, that makes it such a complete and utter nightmare for integration, but what are you going to do. Anyway unfortunately I am not at liberty to give out source for the c# client stuff, however I'd be more than happy to provide help/advice where I can.

  3. #3
    skipperben is offline New Member
    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    5

    Default create a user using C#

    Are there any examples of how to create a user with the soap service?

    I'm trying to add a component to an intranet site for our IT department to create users via an asp.net (C#) page. There are two parts: (1) create a domain user, and (2) create a zimbra account. The domain user is created no problem, but I'm completely clueless how to get connected to the SOAP service to create user. Any input would be much appriciated.

    Thanks!
    ~ Ben

  4. #4
    Rommel is offline Junior Member
    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    5

    Default Same issue..

    Hi
    I am having same issue... I would like to retrieve some messages from a user's inbox.. as well as changing password.

    I am using C# ASP.NET 3.5.... having same problem working with Zimbra SOAP Interface...

    Any help is much appreciated


    Cheers

  5. #5
    skipperben is offline New Member
    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    5

    Default

    I will follow up on Tuesday when I return to work.

  6. #6
    Rommel is offline Junior Member
    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    5

    Default

    Hi Skipperben,, Have you had any luck with ASP.NET & Zimbra SOAP???

    Cheers

  7. #7
    skipperben is offline New Member
    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    5

    Default

    My SOAP experience was NONE before starting to work with Zimbra, that being said, there might be a better way to do what I'm about to post - but this worked for me in my organization for what they wanted (which was to be able to create an email account when an active directory account was created on a webform in our intranet). I expanded it to delete an account too. I set up the code to use 2 classes because if future functionality was needed, I should be able to just expand the classes and not have to rewrite a bunch of code.

    public class SoapParameters
    {

    /// <summary>https://mydomain.com:7071/service/admin/soap/</summary>
    internal string serviceAdminSoapUri { get; set; }

    /// <summary>format: abc@xyz.com (administrator account that can make changes)</summary>
    internal string adminUsername { get; set; }

    /// <summary>(administrator account that can make changes)</summary>
    internal string adminPassword { get; set; }

    internal string authToken { get; set; }

    /// <summary>format: abc@xyz.com (account to which to perform soapCommand on)</summary>
    public string accountUsername { get; set; }

    public string accountFirstName { get; set; }

    public string accountLastName { get; set; }

    public string accountDisplayName
    {
    get { return string.Format("{0} {1}", accountFirstName ,accountLastName); }
    }

    internal string accountId { get; set; }

    public SoapParameters()
    {
    string impersonateDomain = System.Configuration.ConfigurationSettings.AppSett ings["Domain.Settings.ImpersonateDomain"];
    string impersonateUsername = System.Configuration.ConfigurationSettings.AppSett ings["Domain.Settings.ImpersonateUsername"];
    string impersonatePassword = System.Configuration.ConfigurationSettings.AppSett ings["Domain.Settings.ImpersonatePassword"];
    string zimbraServiceAdminSoapUri = System.Configuration.ConfigurationSettings.AppSett ings["Domain.Settings.ZimbraServiceAdminSoapUri"];
    adminUsername = string.Format("{0}@{1}", impersonateUsername, impersonateDomain);
    adminPassword = impersonatePassword;
    serviceAdminSoapUri = zimbraServiceAdminSoapUri;
    }

    // http://zimbra.svn.sourceforge.net/vi...soap-admin.txt

    public class AccountService
    {

    private enum SoapMessages
    {
    AuthenticationToken,
    CreateAccount,
    RemoveAccount,
    Account
    }

    /// <summary>Get First and Last Name of an account based on email address</summary>
    /// <param name="param">just include an email address</param>
    public static SoapParameters Read(SoapParameters param)
    {
    GetAdministratorAuthenticationToken(param);
    GetAccount(param);
    return param;
    }

    public static void Create(SoapParameters param)
    {
    GetAdministratorAuthenticationToken(param);
    CreateAccountRequest(param);
    }

    /// <summary>Remove an account based on email address</summary>
    /// <param name="param">just include an email address</param>
    public static void Delete(SoapParameters param)
    {
    GetAdministratorAuthenticationToken(param);
    GetAccount(param);
    RemoveAccountRequest(param);
    }

    private static void GetAdministratorAuthenticationToken(SoapParameters param)
    {
    XmlDocument doc = GetResponseDoc(param, SoapMessages.AuthenticationToken);
    param.authToken = doc.GetElementsByTagName("authToken").Item(0).Inne rXml;
    }

    private static void CreateAccountRequest(SoapParameters param)
    {
    XmlDocument doc = GetResponseDoc(param, SoapMessages.CreateAccount);
    try
    {
    string value = doc.GetElementsByTagName("CreateAccountResponse"). Item(0).ChildNodes[0].Attributes["id"].Value;
    Guid guid = new Guid(value);
    param.accountId = guid.ToString();
    }
    catch
    {
    throw new Exception("Account Did Not Appear To Be Created.");
    }
    }

    public static void GetAccount(SoapParameters param)
    {
    XmlDocument doc = GetResponseDoc(param, SoapMessages.Account);
    param.accountFirstName = null;
    param.accountLastName = null;
    param.accountId = null;
    string tag = "GetAccountResponse";
    string attr;
    string value;
    int i = 0;
    int max = doc.GetElementsByTagName(tag).Item(0).ChildNodes[0].ChildNodes.Count;

    for (int x = 0; x < doc.GetElementsByTagName(tag).Item(0).ChildNodes[0].Attributes.Count; x++)
    {
    attr = doc.GetElementsByTagName(tag).Item(0).ChildNodes[0].Attributes[x].Name.ToLower();
    value = doc.GetElementsByTagName(tag).Item(0).ChildNodes[0].Attributes[x].InnerText;
    switch (attr)
    {
    case "id":
    try
    {
    Guid guid = new Guid(value);
    param.accountId = guid.ToString();
    }
    catch { }
    break;
    }
    }

    while (i < max)
    {
    attr = doc.GetElementsByTagName("GetAccountResponse").Ite m(0).ChildNodes[0].ChildNodes[i].Attributes[0].Value.ToLower();
    value = doc.GetElementsByTagName("GetAccountResponse").Ite m(0).ChildNodes[0].ChildNodes[i].InnerText;
    switch (attr)
    {
    case "givenname":
    param.accountFirstName = value;
    break;
    case "sn":
    param.accountLastName = value;
    break;
    }
    i = (param.accountFirstName == null || param.accountLastName == null) ? i + 1 : max;
    }

    }

    private static void RemoveAccountRequest(SoapParameters param)
    {
    XmlDocument doc = GetResponseDoc(param, SoapMessages.RemoveAccount);
    if (doc == null)
    throw new Exception("Unsure if account was removed, please have administrator check.");
    }

    private static XmlDocument GetResponseDoc(SoapParameters param, SoapMessages message)
    {
    string soapMessage = SoapMessageBuilder(message, param);
    XmlDocument requestDoc = new XmlDocument();
    requestDoc.LoadXml(soapMessage);
    HttpWebRequest request = HttpWebRequestBuilder(param.serviceAdminSoapUri);
    Stream stm = request.GetRequestStream();
    requestDoc.Save(stm);
    stm.Close();
    WebResponse resp = request.GetResponse();
    stm = resp.GetResponseStream();
    StreamReader r = new StreamReader(stm);
    XmlDocument responseDoc = new XmlDocument();
    responseDoc.LoadXml(r.ReadToEnd());
    return responseDoc;
    }

    private static HttpWebRequest HttpWebRequestBuilder(string serviceAdminSoapUri)
    {
    HttpWebRequest retVal = (HttpWebRequest)WebRequest.Create(serviceAdminSoap Uri);
    retVal.Headers.Add("SOAPAction", "\"\"");
    retVal.ContentType = "text/xml;charset=\"utf-8\"";
    retVal.Accept = "text/xml";
    retVal.Method = "POST";
    return retVal;
    }

    private static string SoapMessageBuilder(SoapMessages message, SoapParameters param)
    {
    string retVal = "";
    switch (message)
    {
    case SoapMessages.AuthenticationToken:
    retVal = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
    "<soap:Header>" +
    "<context xmlns=\"urn:zimbra\"/>" +
    "</soap:Header>" +
    "<soap:Body>" +
    "<AuthRequest xmlns=\"urn:zimbraAdmin\">" +
    "<name>" + param.adminUsername + "</name>" +
    "<password>" + param.adminPassword + "</password>" +
    "</AuthRequest>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    break;
    case SoapMessages.CreateAccount:
    retVal = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
    "<soap:Header>" +
    "<context xmlns=\"urn:zimbra\">" +
    "<authToken>" + param.authToken + "</authToken>" +
    "</context>" +
    "</soap:Header>" +
    "<soap:Body>" +
    "<CreateAccountRequest xmlns=\"urn:zimbraAdmin\">" +
    "<name>" + param.accountUsername +"</name>" +
    "<password></password>" +
    "<a n=\"givenName\">" + param.accountFirstName + "</a>" +
    "<a n=\"sn\">" + param.accountLastName + "</a>" +
    "<a n=\"displayName\">" + param.accountDisplayName + "</a>" +
    "</CreateAccountRequest>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    break;
    case SoapMessages.RemoveAccount:
    retVal = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
    "<soap:Header>" +
    "<context xmlns=\"urn:zimbra\">" +
    "<authToken>" + param.authToken + "</authToken>" +
    "</context>" +
    "</soap:Header>" +
    "<soap:Body>" +
    "<DeleteAccountRequest xmlns=\"urn:zimbraAdmin\">" +
    "<id>" + param.accountId + "</id>" +
    "</DeleteAccountRequest>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    break;
    case SoapMessages.Account:
    retVal = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
    "<soap:Header>" +
    "<context xmlns=\"urn:zimbra\">" +
    "<authToken>" + param.authToken + "</authToken>" +
    "</context>" +
    "</soap:Header>" +
    "<soap:Body>" +
    "<GetAccountRequest xmlns=\"urn:zimbraAdmin\">" +
    "<account by=\"name\">" + param.accountUsername + "</account>" +
    "</GetAccountRequest>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    break;
    }
    return retVal;
    }

    }

    ... and finally, an example of use:

    private static void CreateNewZimbraAccount(string username, string domainName, string firstName, string lastName)
    {
    SoapParameters myParam = new SoapParameters()
    {
    accountUsername = string.Format("{0}@{1}", username, domainName),
    accountFirstName = firstName,
    accountLastName = lastName,
    };
    Domain.Zimbra.AccountService.Create(myParam);
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 31
    Last Post: 12-15-2007, 09:05 PM
  2. Can't start Zimbra!
    By zibra in forum Administrators
    Replies: 5
    Last Post: 03-22-2007, 11:34 AM
  3. dspam logrotate errors
    By michaeln in forum Users
    Replies: 7
    Last Post: 02-19-2007, 12:45 PM
  4. Zimbra server crashed
    By goetzi in forum Administrators
    Replies: 6
    Last Post: 03-25-2006, 01:00 PM
  5. FC3 Install and no zimbra ?
    By aws in forum Installation
    Replies: 10
    Last Post: 10-09-2005, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •