Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-2008, 08:31 PM
Starter Member
 
Posts: 1
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.
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 09:04 AM
Senior Member
 
Posts: 58
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.
Reply With Quote
  #3 (permalink)  
Old 06-03-2009, 10:48 PM
New Member
 
Posts: 3
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
Reply With Quote
  #4 (permalink)  
Old 09-05-2009, 10:19 AM
Junior Member
 
Posts: 6
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
Reply With Quote
  #5 (permalink)  
Old 09-06-2009, 08:25 AM
New Member
 
Posts: 3
Default

I will follow up on Tuesday when I return to work.
Reply With Quote
  #6 (permalink)  
Old 09-08-2009, 03:26 AM
Junior Member
 
Posts: 6
Default

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

Cheers
Reply With Quote
  #7 (permalink)  
Old 09-08-2009, 09:32 AM
New Member
 
Posts: 3
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);
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.