Connect to DocuWare
In order to connect to DocuWare you can use the ServiceConnection class. Pass either a user name and password or a token to the Create method.
The DocuWare Platform supports also NTLM authentication. If you prefer this authentication method you can use CreateWithWindowsAuthentication method.
If you need to specify display language and/or format culture you must specify WebRequestHandler with CookieContainer and add "DWLanguage" and/or "DWFormatCulture" cookies to it.
Create a service connection
If you have only one organization in your system, you do no need to specify it. In case there are more than a single organization in your system, the organization name must be specified. The organization is specified with an optional parameter.
In case you want to enable client-side caching you must provide a WebRequestHandler instance.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Net.Http;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
static Uri uri = new Uri("http://chw-dw-03/docuware/platform");
public static ServiceConnection Connect()
{
return ServiceConnection.Create(uri, "admin", "admin");
}
public static ServiceConnection ConnectWithUserAgent()
{
return ServiceConnection.Create(uri, "admin", "admin",
userAgent: new System.Net.Http.Headers.ProductInfoHeaderValue[] {
new System.Net.Http.Headers.ProductInfoHeaderValue("DocuWare+.NET+API+Test+Client", "1.0")
});
}
public static ServiceConnection ConnectWithOrg()
{
return ServiceConnection.Create(uri, "admin", "admin", organization: "Peters Engineering");
}
public static ServiceConnection ConnectWithCaching()
{
var handler = new WebRequestHandler() { CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default) };
return ServiceConnection.Create(uri, "admin", "admin", httpClientHandler: handler);
}
public static ServiceConnection ConnectWithNTLM()
{
return ServiceConnection.CreateWithWindowsAuthentication(uri, "Administrator", "admin");
}
public static ServiceConnection ConnectWithDefaultUser()
{
return ServiceConnection.CreateWithWindowsAuthentication(uri, System.Net.CredentialCache.DefaultCredentials);
}
public static ServiceConnection ConnectWithDisplayLanguageAndFormatCulture()
{
// Create WebRequestHandler with cookie container
var handler = new WebRequestHandler()
{
CookieContainer = new CookieContainer(),
UseCookies = true,
};
//Set format culture to German
handler.CookieContainer.Add(new Cookie("DWFormatCulture", "de", "/", "localhost"));
//Set display language to German
handler.CookieContainer.Add(new Cookie("DWLanguage", "de", "/", "localhost"));
return ServiceConnection.Create(uri, "admin", "admin", httpClientHandler: handler);
}
}
}
Create a service connection asynchronously
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Net.Http;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class ExamplesAsync
{
static Uri uri = new Uri("http://chw-dw-03/docuware/platform");
public static Task<ServiceConnection> ConnectWithCancellationTokenAsync(System.Threading.CancellationToken token)
{
return ServiceConnection.CreateAsync(uri, "admin", "admin", new ServiceConnectionLoginData()
{
Transport = new ServiceConnectionTransportData() { CancellationToken = token }
});
}
public static async Task<ServiceConnection> ConnectAsync()
{
return await ServiceConnection.CreateAsync(uri, "admin", "admin").ConfigureAwait(false);
}
public static async Task<ServiceConnection> ConnectWithOrgAsync()
{
return await ServiceConnection.CreateAsync(uri, "admin", "admin", organization: "Peters Engineering").ConfigureAwait(false);
}
public static async Task<ServiceConnection> ConnectWithCachingAsync()
{
var handler = new WebRequestHandler() { CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default) };
return await ServiceConnection.CreateAsync(uri, "admin", "admin", httpClientHandler: handler).ConfigureAwait(false);
}
public static async Task<ServiceConnection> ConnectWithNTLMAsync()
{
return await ServiceConnection.CreateWithWindowsAuthenticationAsync(uri, "Administrator", "admin").ConfigureAwait(false);
}
public static async Task<ServiceConnection> ConnectWithDefaultUserAsync()
{
return await ServiceConnection.CreateWithWindowsAuthenticationAsync(uri, CredentialCache.DefaultCredentials).ConfigureAwait(false);
}
public static ServiceConnection ConnectWithJwtAsync()
{
return ServiceConnection.CreateWithJwtAsync(uri, accessToken, DWProductTypes.PlatformService);
}
public static async Task<ServiceConnection> ConnectWithDisplayLanguageAndFormatCulture()
{
// Create WebRequestHandler with cookie container
var handler = new WebRequestHandler()
{
CookieContainer = new CookieContainer(),
UseCookies = true,
};
//Set format culture to German
handler.CookieContainer.Add(new Cookie("DWFormatCulture", "de", "/", "localhost"));
//Set display language to German
handler.CookieContainer.Add(new Cookie("DWLanguage", "de", "/", "localhost"));
return await ServiceConnection.CreateAsync(uri, "admin", "admin", httpClientHandler: handler).ConfigureAwait(false);
}
}
}