How to provision Open-Xchange with C# and SOAP

Here is an example on how create a C# project in Microsoft Visual Studio 2010.

NOTE: please use /webservices instead of /servlet/axis2/services since the latter is deprecated and might be removed at any time.


Create a web reference

In your C# project, right click on References and then on Add Service Reference:

Add service reference.png

In the dialogue click on Advanced:

Add service reference click advanced.png

In the following dialogue, select Add Web Reference:

Service reference settings.png

and in the URL input field enter the URL to your open-xchange servers OXContextService:

Add ox context reference.png

after clicking on Add Reference, the new service should be visible like shown below:

Reference added.png

Example code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OXSOAPBranding.OXContextService;

namespace OXSOAPBranding
{
   class Program
   {
       static void Main(string[] args)
       {
           OXContextService.OXContextService ctxsrv = new OXContextService.OXContextService();

           // define credentials
           Credentials creds = new Credentials() { login = "oxadminmaster", password = "secret" };
            
           // Context Admin user
           User oxadmin = new User();
           oxadmin.name = "oxadmin";
           oxadmin.sur_name = "Context";
           oxadmin.given_name = "Admin";
           oxadmin.display_name = "Context Admin";
           oxadmin.primaryEmail = oxadmin.email1 = "oxadmin@example.com";
           oxadmin.password = "secret";

           // Context for the Groupware4You brand
           Context ctx_gw4u = new Context();
           ctx_gw4u.id = 424242;
           ctx_gw4u.idSpecified = true;
           ctx_gw4u.maxQuota = 5000;
           ctx_gw4u.maxQuotaSpecified = true;
           ctx_gw4u.name = "Groupware4You";
           Entry[] entries_gw4u = new Entry[1] { new Entry() { key = "types", value = "gw4u" } };
           SOAPMapEntry[] attrs_gw4u = new SOAPMapEntry[] {new SOAPMapEntry() { key = "taxonomy", value = entries_gw4u} };
           ctx_gw4u.userAttributes = attrs_gw4u;

           try
           {
               // create the context and
               ctxsrv.create(ctx_gw4u, oxadmin, creds);
               // get it back to check
               Context ret = ctxsrv.getData(ctx_gw4u, creds);
               // whether attributes have been set
               SOAPMapEntry[] attrs = ret.userAttributes;
               if (null != attrs && attrs.Length > 0)
               {
                   Entry[] ents = attrs[0].value;
                   if (null != ents && ents.Length > 0)
                   {
                       Entry e = ents[0];
                       Console.WriteLine(ret.name + " : " + e.key + " -> " + e.value);
                   }
               }
               // cleanup
               ctxsrv.delete(new OXContextService.delete() { ctx = ctx_gw4u, auth = creds });

           }
           catch (Exception ex)
           {
               System.Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
           }
           // wait for input
           System.Console.ReadLine();
       }
   }
}