Il server permettere l’invocazione dei metodi del client da remoto mediante la tecnologia WCF, sul quale sono esposti due endpoint:
Le operazioni disponibili sono:
xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> startup> <system.serviceModel> <bindings> <webHttpBinding> <binding name="webBinding"> binding> webHttpBinding> <basicHttpBinding> <binding name="http" openTimeout="00:05:00" receiveTimeout="00:15:00" sendTimeout="00:05:00" maxBufferSize="2000000000" maxReceivedMessageSize="2000000000" /> basicHttpBinding> bindings> <services> <service name="IToolS.Server.ClientsService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="http" name="basicHttpEndPoint" contract="IToolS.Server.IClientsService"> <identity> <dns value="localhost" /> identity> endpoint> <endpoint address="mex" binding="mexHttpBinding" name="mexHttpEndPoint" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:50000/ClientsServerBasicHttp/" /> baseAddresses> host> service> <service behaviorConfiguration="webHttpServiceBehavior" name="IToolS.Server.ClientsServiceWeb"> <endpoint address="" behaviorConfiguration="ClientsWeb" binding="webHttpBinding" bindingConfiguration="webBinding" name="webHttpEndPoint" contract="IToolS.Server.IClientsServiceWeb" /> <host> <baseAddresses> <add baseAddress="http://localhost:50000/ClientsServerWeb/" /> baseAddresses> host> service> <service name="IToolS.Server.CrossDomain"> <endpoint address="" behaviorConfiguration="CrossDomain" binding="webHttpBinding" contract="IToolS.Server.ICrossDomain" /> <host> <baseAddresses> <add baseAddress="http://localhost:50000/" /> baseAddresses> host> service> services> <behaviors> <endpointBehaviors> <behavior name="CrossDomain"> <webHttp /> behavior> <behavior name="ClientsWeb"> <webHttp /> behavior> endpointBehaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False"/> behavior> <behavior name="webHttpServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false"/> <serviceThrottling /> behavior> serviceBehaviors> behaviors> system.serviceModel> configuration>
Il codice per configurare un server IToolS è il seguente:
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace TestIToolSServer { static class Program { static void Main() { IToolS.Components.ComponentBase.RaiseEventsOnMainThread = false; IToolS.Components.IOServers.IOServer ioServer1 = new IToolS.Components.IOServers.IOServer(); IToolS.Components.Communication.Group group1 = new IToolS.Components.Communication.Group(); IToolS.Components.Communication.Variable variable1 = new IToolS.Components.Communication.Variable(); IToolS.Components.Communication.Variable variable2 = new IToolS.Components.Communication.Variable(); IToolS.Components.Communication.Client client1 = new IToolS.Components.Communication.Client(); IToolS.Components.Communication.Clients clients1 = new IToolS.Components.Communication.Clients(); IToolS.Server.ClientsServer clientsServer1 = new IToolS.Server.ClientsServer(); ioServer1.Name = "Memory"; group1.Items.AddRange(new IToolS.Components.Communication.Variable[] { variable1, variable2 }); variable1.Address = "0"; variable1.VariableName = "variable1"; variable1.Changed += new IToolS.Data.ChangedEventHandler(variable_Changed); variable2.Address = "1"; variable2.VariableName = "variable2"; variable2.Changed += new IToolS.Data.ChangedEventHandler(variable_Changed); client1.ClientName = "client1"; client1.Group = group1; client1.IOServer = ioServer1; clients1.Items.Add(client1); clientsServer1.Authentication.Enable = true; clientsServer1.Authentication.Password = "1234"; clientsServer1.Authentication.UserName = "MyName"; clientsServer1.Clients = clients1; clients1.Start(); clientsServer1.Start(); Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); clientsServer1.Stop(); clients1.Stop(); client1.StopIOServer(); } private static void variable_Changed(object sender, IToolS.Data.ChangedEventArgs e) { Console.WriteLine(((IToolS.Components.Communication.Variable)sender).VariableName + " value = " + Convert.ToString(e.NewValue)); } } }
Esegue l'autenticazione sul server
http://localhost:50000/ClientsServerWeb/Login?userName=MyName&password=1234
Scrivere il valore 1000 nella variabile "variable1" associata al client "client1"
http://localhost:50000/ClientsServerWeb/ClientWrite?clientName=client1&variableName=variable1&value=1000
IToolS Blog