RO/SDK CodeFirst how define structs,arrays,...?

How can i define structs,arrays and so on in code first server in C#?

i can’t find any information about this in doc or talk

for instance this rodl types

 <Struct Name="ErrorStruct" UID="{1AE661F3-CD30-4420-B134-EA58F36B1B3E}" AutoCreateParams="1">
 <Elements> 
   <Element Name="Nr" DataType="Integer"></Element>
   <Element Name="Description" DataType="Widestring"></Element>
 </Elements>
</Struct>

> <Array Name="IntegerArray" UID="{D7230580-CDDA-4A8F-BAA6-C19E9353CD2F}">
> <ElementType DataType="Integer"/>
> </Array>

For the struct “ErrorStruct” simply create a class like that:

public class ErrorStruct : RemObjects.SDK.Types.ComplexType
{
    public int Nr {get; set;}
    public string Description {get; set;}
}

Than use this class in a method, that is decorated with the [ServiceMethod] attribute.

[ServiceMethod]    
public ErrorStruct GetLastError()
{
   return new ErrorStruct() {1,"Test"};
}

That’s all.

There’s no need to define array types in CodeFirst. The SDK creates them dynamically for you.

[ServiceMethod]    
public ErrorStruct[] GetAllErrors()
{
    var LErrors = new ErrorStruct[]
    {
        new ErrorStruct() {1,"Test1"},
        new ErrorStruct() {2,"Test2"},
        new ErrorStruct() {3,"Test3"}
    };
    return LErrors;
}

[ServiceMethod]
public int[] GetSomeIntegers()
{
    return new int[] {1,2,3,4,5};
}
1 Like

That is a part of the yet to be published RO SDK tutorial.


Supported data types

Not every .NET data type can be used in the interface published by a Code first server.

Only following data types are supported:

  • RemObjects.SDK.Binary (see note below)
  • Boolean
  • DateTime
  • Decimal
  • Double
  • Guid
  • Int32
  • In64
  • String (see note below)
  • System.Xml.XmlNode
  • Object (see note below)
  • Class inherited from RemObjects.SDK.ComplexType (see note below)
  • Enumeration
  • Arrays of supported data types

Notes:

  • RemObjects.SDK.Binary is a wrapper over the System.IO.MemoryStream type

  • String values can be serialized and deserialized in 3 different incompatible encodings:

  • ANSI

  • UTF8

  • Unicode (comatible with the Delphi WideString data type)

  • List of supported value data types of Object-typed parameters or properties is very limited:

  • null value

  • System.Boolean

  • System.Byte

  • System.SByte

  • System.DateTime

  • System.Decimal

  • System.Double

  • System.Int16

  • System.Int32

  • System.Int64

  • System.String (serialized using the UTF8 encoding)

  • System.Guid

  • Public properties of classes inherited from RemObjects.SDK.ComplexType should have supported data types (including other ComplexType descendants)

Service definitions

Sample CodeFirst service definition:

[Service] 
public class SampleService : RemObjects.SDK.Server.Service 
{ 
    [ServiceMethod] 
    public string DoSomething(string someValue) 
    { 
        return "No Result"; 
    } 
} 

A class is considered as a CodeFirst service definition if these conditions are met:

  • The class is inherited from the RemObjects.SDK.Server.Service class directly or indirectly
  • The class is marked with the Service attribute
  • The class is public

The method is considered as a published if these conditions are met:

  • The method is public
  • Method is marked with the [ServiceMethod] attribute

The following restrictions are applied to the published methods:

  • Published method names should be unique
  • Method result type (if any) and method parameter types should be ones of the supported types list
    If these restrictions are not met the server app will be able to compile but will throw an exception at runtime.

The following optional attributes can be applied to the service definition:
ServiceRequiresLogin
Sets the service instance’s RequiresSession property to true at runtime. Service marked with this attribute will require user to first log in

RemObjects.SDK.Server.ClassFactories.StandardClassFactory
RemObjects.SDK.Server.ClassFactories.PerClientClassFactory
RemObjects.SDK.Server.ClassFactories.SingletonClassFactory
Defines a class factory that will be used to instantiate the service instances to server the incoming requests. By default the Standart class factory is used

Abstract
Marks the service as abstract. Abstract services are published in the server’s RODL but cannot be called directly

Documentation
Sets the documentation text for the service

The required Service attribute has an optional Name parameter that can be used to alter the name that is used to publish the service:
[Service(Name = "NewServiceName")]

The following optional attributes can be applied to the service method definitions:
StreamAs
Sets encoding used to send string data. Can be applied to method or its parameters. When applied to the method itself this attribute affects the method result serialization.
This attribute is ignored for any non-string parameters

Documentation
Sets the documentation text for the service method or its parameters. Can be applied to method or its parameters

The required ServiceMethod attribute has an optional Name parameter that can be used to alter the name that is used to publish the service:
[ServiceMethod(Name = "NewMethodName")]

Server-Sent Events definitions

Sample Server-Sent Events interface definition:

[EventSink] 
public interface IChatEvents : IROEventSink 
{ 
    void MessageReceived(string sender, string message); 
} 

An interface is considered as a CodeFirst Server-Sent Events interface definition if these conditions are met:

  • The interface is inherited from the RemObjects.SDK.IROEventSink interface directly or indirectly
  • The interface is marked with the EventSink attribute
  • The interface is public

The following restrictions are applied to the published methods:

  • Interface Method names should be unique
  • Interface methods should not return any results (ie their result type should be void).
  • Interface method parameter types should be ones of the supported types list

The following optional attribute can be applied to the interface definition:
Documentation
Sets the documentation text for the events interface

The required EventSink attribute has an optional Name parameter that can be used to alter the name that is used to publish the service:
[EventSink(Name = "NewEventsName")]

The following optional attributes can be applied to the interface method definitions:
StreamAs
Sets encoding used to send string data. Can be applied to method parameters.
This attribute is ignored for any non-string parameters

Documentation
Sets the documentation text for the interface method or its parameters. Can be applied to method or its parameters

Structure (complex type) definitions

Sample CodeFirst Structure definition:

public class SampleStructure : ComplexType 
{ 
    public string StringProperty { get; set; } 
    public int IntegerProperty { get; set; } 
} 

A class is considered as a CodeFirst Structure definition if these conditions are met:

  • The class is inherited from the RemObjects.SDK.Types.ComplexType class directly or indirectly
  • The class or any of its ancestor classes is used as data type of a parameter in a service or event interface method, or as a data type of a Structure or an Exception property
  • The class is public

The following restrictions are applied to the class properties:

  • Indexed properties are not supported
  • Parameter data types should be ones of the supported types list

The following optional attribute can be applied to the structure definition:
Documentation
Sets the documentation text for the structure

The following optional attributes can be applied to the structure properties:
StreamAs
Sets encoding used to send string data.
This attribute is ignored for any non-string properties
Documentation
Sets the documentation text for property

Enumeration definitions

Sample CodeFirst enumeration definition:

public enum SampleEnum 
{ 
    First, 
    Second, 
    Third 
} 

An enum is considered as a valid CodeFirst Enum definition if these conditions are met:

  • The enum element values start from 0 and are sequential. Enum with directly set element values (including Flag enums) are not supported
  • The enum is used as data type of a parameter in a service or event interface method, or as a data type of a Structure or an Exception property
  • The enum is public

The following optional attribute can be applied to the enum definition:
Documentation
Sets the documentation text for the enumeration definition

The following optional attribute can be applied to the enum elements:
Documentation
Sets the documentation text for the enumeration element

Exception definitions

Sample CodeFirst exception:

public class SampleException : ServerException 
{ 
    public string AdditionalData { get; set; } 
} 

A class is considered as a CodeFirst Exception definition if these conditions are met:

  • The class is inherited from the RemObjects.SDK.Types.ServerException class directly or indirectly
  • The class is public

The following restrictions are applied to the class properties:

  • Indexed properties are not supported
  • Parameter data types should be ones of the supported types list

The following optional attribute can be applied to the exception definition:
Documentation
Sets the documentation text for the exception

The following optional attributes can be applied to the exception properties:
StreamAs
Sets encoding used to send string data.
This attribute is ignored for any non-string properties

Documentation
Sets the documentation text for property

2 Likes