示例#1
0
 public static WCFDatabase InitializeDb()
 {
     if (instance == null)
     {
         instance = new WCFDatabase();
     }
     return(instance);
 }
示例#2
0
文件: Program.cs 项目: Dexter255/SBES
        static void Main(string[] args)
        {
            //Debugger.Launch();
            WCFDatabase db = WCFDatabase.InitializeDb();

            //uzmemo username od servera kako bismo uzeli certificate uz pomoc toga
            String serviceCertificateCN = Formatter.ParseName(WindowsIdentity.GetCurrent().Name);

            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

            string address = "net.tcp://localhost:9999/WCFService";

            ServiceHost serviceHost = new ServiceHost(typeof(WCFService));

            serviceHost.AddServiceEndpoint(typeof(IWCFService), binding, address);

            //kazemo da ne gleda da li je povucen sertifikat i setujemo .cer fajl od servera
            serviceHost.Credentials.ClientCertificate.Authentication.RevocationMode            = X509RevocationMode.NoCheck;
            serviceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;
            serviceHost.Credentials.ServiceCertificate.Certificate = CertManager.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, serviceCertificateCN);

            serviceHost.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
            serviceHost.Description.Behaviors.Add(new ServiceDebugBehavior()
            {
                IncludeExceptionDetailInFaults = true
            });


            serviceHost.Authorization.ServiceAuthorizationManager = new AuthorizationManager();

            //polisa sadrzi uslove koje omogucavaju evaluaciju korisnika(da li ima pravo pristupa nekoj metodi)
            //na osnovu polise radimo proveru
            serviceHost.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.Custom;
            List <IAuthorizationPolicy> policies = new List <IAuthorizationPolicy>();

            policies.Add(new CustomPolicy());
            serviceHost.Authorization.ExternalAuthorizationPolicies = policies.AsReadOnly();

            serviceHost.Description.Behaviors.Remove <ServiceSecurityAuditBehavior>();
            ///////////////////////// LOGGER /////////////////////////
            NetTcpBinding bindingLogger = new NetTcpBinding();

            bindingLogger.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            string          addressLogger   = "net.tcp://localhost:10000/WCFLogger";
            EndpointAddress endpointAddress = new EndpointAddress(new Uri(addressLogger));

            //////////////////////////////////////////////////////////


            WCFServiceLoggerConnection.InitializeService(bindingLogger, endpointAddress);

            serviceHost.Open();
            Console.WriteLine("WCFService is opened. Press <enter> to finish and save databases...");
            Console.ReadLine();

            serviceHost.Close();

            db.SerializeData();
        }