-
Notifications
You must be signed in to change notification settings - Fork 14
ServiceContract (Attribute)
The ServiceContractAttribute is for communicate services between client and server when you add a class that implemented one or more interfaces SignalGo find ServiceContractAttribute over your service class or interface to make service methods and skip another.
If your service interface have implemented another interfaces signalGo dont ignore base interfaces methods, signal Go just ignore parent of interface and classes that don't have ServiceContractAttribute.
For Example:
[SignalGo.Shared.DataTypes.ServiceContract("TestServerModel", ServiceType.ServerService, InstanceType = SignalGo.Shared.DataTypes.InstanceType.SingleInstance)]
public interface ITestServerModel
{
Tuple<string> HelloWorld(string yourName);
}
In this interface we have a ServiceContractAttribute top of our class and his name is "TestServerModel" and have one method.
If we have this:
public interface ITestServerModelBase
{
Tuple<bool> Logout(string yourName);
}
[SignalGo.Shared.DataTypes.ServiceContract("TestServerModel", ServiceType.ServerService, InstanceType = SignalGo.Shared.DataTypes.InstanceType.SingleInstance)]
public interface ITestServerModel : ITestServerModelBase
{
Tuple<string> HelloWorld(string yourName);
}
public interface ITestServerModelParent : ITestServerModel
{
Tuple<bool> Login(string yourName);
}
We have 2 methods for our service: Logout,HelloWorld
Why "Login" method is not inside our service-level? because our ServiceContract attribute is top of "ITestServerModel" interface and "Login" method is outside of service contract-level, is in its parent not its child or itself.
Example:
[SignalGo.Shared.DataTypes.ServiceContract("TestServerModel", ServiceType.ServerService, InstanceType = SignalGo.Shared.DataTypes.InstanceType.SingleInstance)]
public class TestServerModel
{
Tuple<string> HelloWorld(string yourName);
}
InstanceType parameter help you to change plan of service class instance, server will create your services class in runtime when client connection is established. You can change the plan with two types:
- SingleInstance: Just one instance will be create in runtime when clients are connected,if you have 20 connection in your server you will have 1 instance of your service class in memory
- MultipeInstance: Create instance of service class per client connection,if you have 20 connection in your server you will have 20 instance of your service class in memory (this is default value of attribute if you don't set this value)
ServiceType parameter will help you to change plan of service class methods that client need, server will create your services class in runtime when client connection is established. You can change the plan with four types:
- ServerService: your server class is service of server that have methods and client can call that methods it will use duplex protocol.
- ClientService: when your service is your client side service that have methods and server can call that methods.
- HttpService: when your service is your server side service that have methods and client can call that methods by http protocol calls.
- StreamService: when your service is your server side service that have stream methods and client can call that methods to download or upload service.
- OneWayService: this works http service but not used http protocol, it's signalgo protocol oneway mean after client send data and call a server service, client connection will close from server.
[SignalGo.Shared.DataTypes.ServiceContract("TestServerModel", ServiceType.ServerService, InstanceType = SignalGo.Shared.DataTypes.InstanceType.SingleInstance)]
public interface ITestServerModel : ITestServerModelBase
{
Tuple<string> HelloWorld(string yourName);
}
check here: https://github.com/SignalGo/signalgo-samples