NetServer Services API
The SuperOffice.NetServer.Service proxy client is provided to give access to the following types of web service endpoints
Using this NetServer Services API, you must use an application configuration file. Read more about configuration requirements and options in the NetServer configuration documentation.
- SOAP: WCF-based IIS application
SuperOffice publishes web service proxies that can be used by clients to access the service endpoints.
An important aspect of NetServer web service development is its deployment flexibility. It's capable of being embedded in a domain-centric client, or used by a web application across the internet.
Dependency injection
Since version 10, SuperOffice uses dependency injection to establish configuration options and parameters.
There are many ways to orchestrate the configuration of the NetServer Core API. The most common way is to use the Startup
class, which is a convention used in ASP.NET Core applications. However, this explanation will not make any assumptions about the type of application you are building and will instead explicitly add an IStartup interface for demonstration purposes.
Session Mode
SuperOffice requires a context provider to be specified when configuring the NetServer Core API. The context provider is responsible for providing the principal context for the current user. There are several default implementations of ISoContextProvider located in SoCore.
- ThreadContextProvider
- ContextContextProvider
- ProcessContextProvider
Another is HttpContextProvider, located in SuperOffice.DCFWeb, used be the SuperOffice web client.
```csharp
public interface IStartup
{
IConfigurationRoot Configuration { get; set; }
void Configure(IServiceCollection services);
void ConfigureServices(IServiceProvider serviceProvider);
}
public class Startup : IStartup
{
public IConfigurationRoot Configuration { get; set; }
public virtual void Configure(IServiceCollection services)
{
services.AddLogging(a =>
{
a.AddConfiguration(Configuration.GetSection("Logging"));
a.ClearProviders();
a.AddConsole();
});
services.AddNetServerCore<ThreadContextProvider>(options => OnConfigureNetServerCore(options));
services.AddSoDatabase(options => OnConfigureNetServerLocal(options));
// Add the services implementation for local network use
services.AddServicesImplementation();
// OR.......................
// Add the services proxies for distributed network use
// services.AddServicesProxies();
}
protected virtual void OnConfigureNetServerCore(NetServerCoreOptionsBuilder options)
{
// this option is required for on-premises installations and
// requires that the SuperOffice.Online.dll is added in the
// declared in the SuperOffice Factory DynamicLoad section
// of the configuration file.
/*
See: https://docs.superoffice.com/en/api/netserver/config/factory.html
<Factory>
<DynamicLoad>
<add key="Onsite" value="SuperOffice.Onsite.dll" />
</DynamicLoad>
</Factory>
*/
options.UseOnPremAD();
}
protected virtual void OnConfigureNetServerLocal(NetServerLocalOptionsBuilder options)
{
}
public virtual void ConfigureServices(IServiceProvider serviceProvider)
{
var netServerServiceProvider = serviceProvider.RegisterWithNetServer();
}
}
```
Session Mode
SuperOffice requires a context provider to be specified when configuring the NetServer Core API. The context provider is responsible for providing the principal context for the current user. There are several default implementations of ISoContextProvider located in SoCore.
- ThreadContextProvider
- ContextContextProvider
- ProcessContextProvider
Another is HttpContextProvider, located in SuperOffice.DCFWeb, used be the SuperOffice web client.
Bootstrap the application
The Startup
class is then used to bootstrap the application. The Startup
class is a convention used in ASP.NET Core applications. However, this explanation will not make any assumptions about the type of application you are building and will instead explicitly add an IStartup interface for demonstration purposes.
Read more about authentication options in the SuperOffice authentication documentation.
public class Program
{
public static void Main(string[] args)
{
var startup = new Startup();
var config = new Dictionary<string, string>
{
{"Logging:LogLevel:Default", nameof(Microsoft.Extensions.Logging.LogLevel.Warning)},
{"Logging:LogLevel:SuperOffice", nameof(Microsoft.Extensions.Logging.LogLevel.Warning)},
{"Logging:LogLevel:Test", nameof(Microsoft.Extensions.Logging.LogLevel.Information)}
};
startup.Configuration = new ConfigurationBuilder()
.AddInMemoryCollection(config)
.Build();
var services = new ServiceCollection();
services.AddSingleton<IContextInitializer, ExampleContextInitializer>();
startup.Configure(services);
var serviceProvider = services.BuildServiceProvider(true);
startup.ConfigureServices(serviceProvider);
Console.WriteLine("SuperOffice NetServer Core Example");
// See the authentication section for more authentication options.
// https://docs.superoffice.com/en/authentication/onsite/sosession/index.html
using (SoSession.Authenticate("username", "password"))
{
using(ContactAgent contactAgent = new ContactAgent())
{
//Create a new contact Entity with default values set to its properties
ContactEntity myContact = contactAgent.CreateDefaultContactEntity();
//Assign values to properties of basic data types
myContact.Name = "FooBar Inc.";
myContact.Department = "Headquarters";
myContact.NoMailing = true;
//Create an array of EntityElement and assign it to the Phones property
EntityElement[] myPhones = new EntityElement[2];
myPhones[0] = new EntityElement();
myPhones[1] = new EntityElement();
myPhones[0].Value = "0112732006";
myPhones[1].Value = "0713243288";
myContact.Phones = myPhones;
// Set the new contact’s our-contact to associate 2
using(AssociateAgent associateAgent = new AssociateAgent())
{
Associate myAssociate = associateAgent.GetAssociate(2);
myContact.Associate = myAssociate;
}
//Save the Contact Entity and the new person through the ContactAgent
// the returned entity has the contact ID filled in
myContact = contactAgent.SaveContactEntity(myContact);
Console.WriteLine($"New Company {myContact.Name} created with ID {myContact.ContactId}");
}
}
}
}