/*********************************************************************/ /* */ /* AgentService Framework */ /* www.agentservice.it */ /* */ /* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */ /* GNU Lesser General Public License */ /* */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Lesser General Public */ /* License as published by the Free Software Foundation, */ /* version 2.1 of the License. */ /* */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ /* Lesser General Public License for more details. */ /* */ /* You should have received a copy of the GNU Lesser General Public */ /* License along with this library; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /*********************************************************************/ using AgentService; using AgentService.Platform.AMS; using AgentService.Agent; using AgentService.Platform.MTS; using AgentService.Platform.Modules; using AgentService.Agent.Runtime; using System; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Description; using System.Collections.Generic; using System.Xml; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; namespace AgentService.WCFServer { public class ASWCFServer { private Uri address; private Platform.Platform platform; #region Bindings private BasicHttpBinding remBinding; private BasicHttpBinding wpBinding; private BasicHttpBinding ypBinding; private BasicHttpBinding msgBinding; private BasicHttpBinding evdspBinding; #endregion #region Clients private RemoteRegisterClient remc; private RemoteWhitePagesClient wpc; private RemoteYellowPagesClient ypc; private RemoteMsgClient msgc; private RemoteEventsDispatcher evdsp; #endregion #region ServiceHosts private ServiceHost remsvc; private ServiceHost wpsvc; private ServiceHost ypsvc; private ServiceHost msgsvc; private ServiceHost evdspsvc; #endregion #region URIs private Uri remUri; private Uri wpUri; private Uri ypUri; private Uri msgUri; private Uri evdspUri; #endregion public ASWCFServer(Uri add, Platform.Platform plat) { platform = plat; address = add; String baseAddress = address.ToString(); remBinding = new BasicHttpBinding(); wpBinding = new BasicHttpBinding(); ypBinding = new BasicHttpBinding(); msgBinding = new BasicHttpBinding(); evdspBinding = new BasicHttpBinding(); int size = Int32.Parse(this.platform.Configuration.Properties["System.WcfServer.MsgSize"]); msgBinding.MaxReceivedMessageSize = size; msgBinding.MaxBufferSize = size; msgBinding.MaxBufferPoolSize = size; // URIs of the services remUri = new Uri(baseAddress + "ASremc/"); wpUri = new Uri(baseAddress + "ASwpc/"); ypUri = new Uri(baseAddress + "ASypc/"); msgUri = new Uri(baseAddress + "ASmsgc/"); evdspUri = new Uri(baseAddress + "ASevdsp/"); // The services msgc = new RemoteMsgClient(plat.MTS,(IImprovedMessagingModule) plat.Messaging); evdsp = new RemoteEventsDispatcher(msgc, (IImprovedMessagingModule)plat.Messaging); int checkT = Int32.Parse(this.platform.Configuration.Properties["System.WcfServer.CheckTime"]); remc = new RemoteRegisterClient(plat.AMS, plat.MTS,msgc,evdsp,checkT); wpc = new RemoteWhitePagesClient(plat.WhitePageSvc); ypc = new RemoteYellowPagesClient(plat.YellowPageSvc); // ServiceHosts for the service remsvc = new ServiceHost(remc, remUri); wpsvc = new ServiceHost(wpc, wpUri); ypsvc = new ServiceHost(ypc, ypUri); msgsvc = new ServiceHost(msgc, msgUri); evdspsvc = new ServiceHost(evdsp, evdspUri); #region Enabling metadata exposition ServiceMetadataBehavior remMetadata = new ServiceMetadataBehavior(); ServiceMetadataBehavior wpMetadata = new ServiceMetadataBehavior(); ServiceMetadataBehavior ypMetadata = new ServiceMetadataBehavior(); ServiceMetadataBehavior msgMetadata = new ServiceMetadataBehavior(); ServiceMetadataBehavior evdspMetadata = new ServiceMetadataBehavior(); remMetadata.HttpGetEnabled = true; wpMetadata.HttpGetEnabled = true; ypMetadata.HttpGetEnabled = true; msgMetadata.HttpGetEnabled = true; evdspMetadata.HttpGetEnabled = true; remsvc.Description.Behaviors.Add(remMetadata); wpsvc.Description.Behaviors.Add(wpMetadata); ypsvc.Description.Behaviors.Add(ypMetadata); msgsvc.Description.Behaviors.Add(msgMetadata); evdspsvc.Description.Behaviors.Add(evdspMetadata); #endregion if (bool.Parse(this.platform.Configuration.Properties["System.WcfServer.Debug"]) == true) { //DEBUG ServiceDebugBehavior msgDebug = msgsvc.Description.Behaviors.Find(); msgDebug.IncludeExceptionDetailInFaults = true; // Adding endpoints remsvc.AddServiceEndpoint(typeof(IRemoteRegisterClient), remBinding, new Uri("http://localhost:8383/ASremc/"), remUri); wpsvc.AddServiceEndpoint(typeof(IWhitePagesClient), wpBinding, new Uri("http://localhost:8383/ASwpc/"), wpUri); ypsvc.AddServiceEndpoint(typeof(IYellowPagesClient), ypBinding, new Uri("http://localhost:8383/ASypc/"), ypUri); msgsvc.AddServiceEndpoint(typeof(IRemoteMsgClient), msgBinding, new Uri("http://localhost:8383/ASmsgc/"), msgUri); evdspsvc.AddServiceEndpoint(typeof(IRemoteEventsDispatcher), evdspBinding, new Uri("http://localhost:8383/ASevdsp/"), evdspUri); } else { remsvc.AddServiceEndpoint(typeof(IRemoteRegisterClient), remBinding, remUri); wpsvc.AddServiceEndpoint(typeof(IWhitePagesClient), wpBinding, wpUri); ypsvc.AddServiceEndpoint(typeof(IYellowPagesClient), ypBinding, ypUri); msgsvc.AddServiceEndpoint(typeof(IRemoteMsgClient), msgBinding, msgUri); evdspsvc.AddServiceEndpoint(typeof(IRemoteEventsDispatcher), evdspBinding, evdspUri); } } /// /// Opens the WCF server /// public void startServer() { // Opening endpoints remsvc.Open(); wpsvc.Open(); ypsvc.Open(); msgsvc.Open(); evdspsvc.Open(); } /// /// Closes the WCF Server /// public void stopServer() { remsvc.Close(); wpsvc.Close(); ypsvc.Close(); msgsvc.Close(); evdspsvc.Close(); remc.KillPollingThread(); } } }