Inhaltsverzeichnis

Developing the web service

Below you will find a code example as well as information about the required references.

Interfaces

The interfaces relevant for the creation are located in the eBiss.Api.dll to which a reference in the .NET project must be added. Always make sure to use the latest version of the library.
Furthermore you need System.ServiceModel and System.ServiceModel.Web as reference in your project.

eBiss.Api.WebServiceBase

Your web service only needs to inherit from the class eBiss.Api.WebServiceBase. This class provides the required methods to process your received data into eBiss.
It is important that you assign the Document within your method. The example shows the following line:

this.Document = new ExampleRequest() { Info = info };

Explanation:
eBiss always expects messages or their documents for processing data. Since you probably want to process incoming data with eBiss using your webservices, eBiss can only correctly encapsulate the received data for further processing if you assign the document accordingly.

WCF Programming Model

Our example corresponds to the programming model of Microsoft's WCF. You will find more information about the use of the attributes:
https://docs.microsoft.com/de-de/dotnet/framework/wcf/feature-details/wcf-web-http-programming-model-overview

Servicedefinition

Below you will find a template for a simple service implementation whose implementation you can also find in the delivered code under
eBiss3… \StandardTemplates\PluginSample\eBiss.PluginSample.

using eBiss.Api;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
 
namespace eBiss.PluginSamples.WebService
{
    [ServiceContract]
    public class ExampleService : WebServiceBase
    {
        /// <summary>
        /// Sample Call:
        ///   curl -X POST -i 'http://127.0.0.1:8093/TestApi/ExampleMethod' --data-binary @PathToFileName
        ///   
        /// If you have complex data, e.g. WS HTTP binding
        /// </summary>
        /// <returns></returns>
        [OperationContract, WebInvoke(Method = "POST")] // 
        public ExampleResponse ExampleMethod(ExampleRequest req)
        {
            this.Document = req;
 
            WaitForMessageCreated();
 
            return new ExampleResponse(HttpStatusCode.OK);
        }
 
        /// <summary>
        /// Sample call:
        ///     curl -X POST -i 'http://127.0.0.1:8080/GetVariables?info=value1'
        /// </summary>
        /// <param name="filter">Use * for all or variable name</param>
        /// <returns></returns>
        [OperationContract, WebInvoke(Method = "POST", UriTemplate = "/GetVariables?filter={filter}")]
        public Stream GetVariables(string filter)
        {
            WaitForInitialization();
 
            Log.Info($"Call GetVariables(\"{(filter ?? "<null>")}\")");
 
            ResponseVariableInfo rv = new ResponseVariableInfo(HttpStatusCode.OK);
 
            foreach (string key in Variables.Keys)
            {
                if (filter == null || filter == "*" || key.StartsWith(filter, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Info($" add variable '{key}'");
                    rv.Variables.Add(new VariableInfoItem(key, Variables[key].ToString()));
                }
                else
                {
                    Log.Info($" variable '{key}' is not selected by the filter");
                }
            }
 
 
            return EntitiesBase.JsonExporter().ExportToStream(rv);
        }
    }
 
    [DataContract]
    public class ExampleRequest : IMapObjectRoot
    {
        public string Info;
    }
 
    [DataContract]
    public class ExampleResponse
    {
        public HttpStatusCode Status { get; }
 
        public ExampleResponse(HttpStatusCode status)
        {
            Status = status;
        }
    }
}