Open-Xchange-SOAP-C-Sharp: Difference between revisions
From Open-Xchange
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
Here is an example on how create a C# project in Microsoft Visual Studio 2010. | Here is an example on how create a C# project in Microsoft Visual Studio 2010. | ||
== Create a web reference == | |||
In your C# project, right click on ''References'' and then on ''Add Service Reference'': | In your C# project, right click on ''References'' and then on ''Add Service Reference'': | ||
Line 22: | Line 24: | ||
[[File:Reference_added.png]] | [[File: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(); | |||
} | |||
} | |||
} |
Revision as of 13:24, 26 October 2011
How to provision Open-Xchange with C# and SOAP
Here is an example on how create a C# project in Microsoft Visual Studio 2010.
Create a web reference
In your C# project, right click on References and then on Add Service Reference:
In the dialogue click on Advanced:
In the following dialogue, select Add Web Reference:
and in the URL input field enter the URL to your open-xchange servers OXContextService:
after clicking on Add Reference, the new service should be visible like shown below:
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(); } } }