Exemple #1
0
        public static void InstallService(string servicePath, string serviceName, string serviceDisplayName, string serviceDescription, string userName, string password)
        {
            using (SafeServiceHandle hSCManager = OpenSCManager(null, null, ServiceManagerAccess.SC_MANAGER_CREATE_SERVICE))
            {
                if (hSCManager.IsInvalid)
                {
                    throw new Win32Exception();
                }

                SafeServiceHandle svcHandle = CreateService(
                    hSCManager,
                    serviceName,
                    serviceDisplayName,
                    ServiceAccess.SERVICE_ALL_ACCESS,
                    ServiceType.SERVICE_WIN32_OWN_PROCESS,
                    ServiceStartType.SERVICE_DEMAND_START,
                    ServiceErrorControl.SERVICE_ERROR_NORMAL,
                    servicePath,
                    null,
                    0,
                    null,
                    userName,
                    password);

                using (svcHandle)
                {
                    if (svcHandle.IsInvalid)
                    {
                        throw new Win32Exception();
                    }

                    ServiceDescription descriptionStruct = new ServiceDescription
                    {
                        lpDescription = serviceDescription
                    };

                    IntPtr lpInfo = Marshal.AllocHGlobal(Marshal.SizeOf(descriptionStruct));

                    if (lpInfo == IntPtr.Zero)
                    {
                        throw new Win32Exception();
                    }

                    Marshal.StructureToPtr(descriptionStruct, lpInfo, false);

                    if (!ChangeServiceConfig2(svcHandle, ServiceInfoLevel.SERVICE_CONFIG_DESCRIPTION, lpInfo))
                    {
                        Marshal.FreeHGlobal(lpInfo);
                        throw new Win32Exception();
                    }

                    Marshal.FreeHGlobal(lpInfo);

                    if (svcHandle.IsInvalid)
                    {
                        throw new Win32Exception();
                    }
                }
            }
        }
	public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
	{
		foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
		{
			endpoint.Behaviors.Add(new SilverlightFaultEndpointBehavior());
		}
	}
Exemple #3
0
        // Returns the AID of the first found service provider
        public static AID FindService(string serviceName, Agent myAgent, int timeOut)
        {
            AID providerAID = null;
            bool found = false;

            double t1 = PerformanceCounter.GetValue();
            while (!found)
            {
                if (PerformanceCounter.GetValue() - t1 > timeOut)
                    break;

                Application.DoEvents();

                // search for a provider
                DFAgentDescription template = new DFAgentDescription();
                ServiceDescription sd = new ServiceDescription();
                sd.setType(serviceName);
                template.addServices(sd);

                DFAgentDescription[] result = DFService.search(myAgent, template);
                if (result != null && result.Length > 0)
                {
                    providerAID = result[0].getName();
                    found = true;
                }
            }

            return providerAID;
        }
        public static unsafe void CreateService(string lpBinaryPathName, string lpServiceName, string lpDisplayName, string lpDescription, string lpServiceStartName, string lpPassword)
        {
            if (string.IsNullOrWhiteSpace(lpBinaryPathName))
            {
                throw new ArgumentException("Binary path name must not be null nor empty", nameof(lpBinaryPathName));
            }

            if (string.IsNullOrWhiteSpace(lpServiceName))
            {
                throw new ArgumentException("Service name must not be null nor empty", nameof(lpServiceName));
            }

            using (SafeServiceHandle scmHandle = OpenSCManager(null, null, ServiceManagerAccess.SC_MANAGER_CREATE_SERVICE))
            {
                if (scmHandle.IsInvalid)
                {
                    throw new Win32Exception();
                }

                SafeServiceHandle svcHandle = CreateService(
                    scmHandle,
                    lpServiceName,
                    lpDisplayName,
                    ServiceAccess.SERVICE_ALL_ACCESS,
                    ServiceType.SERVICE_WIN32_OWN_PROCESS,
                    ServiceStartType.SERVICE_DEMAND_START,
                    ServiceErrorControl.SERVICE_ERROR_NORMAL,
                    lpBinaryPathName,
                    null,
                    0,
                    null,
                    lpServiceStartName,
                    lpPassword);

                using (svcHandle)
                {
                    if (svcHandle.IsInvalid)
                    {
                        throw new Win32Exception();
                    }

                    ServiceDescription descriptionStruct = new ServiceDescription
                    {
                        lpDescription = lpDescription
                    };

                    fixed (void* lpInfo = new byte[Marshal.SizeOf(descriptionStruct)])
                    {
                        Marshal.StructureToPtr(descriptionStruct, new IntPtr(lpInfo), false);
                        if (!ChangeServiceConfig2(svcHandle, ServiceInfoLevel.SERVICE_CONFIG_DESCRIPTION, lpInfo))
                        {
                            throw new Win32Exception();
                        }

                        Marshal.DestroyStructure(new IntPtr(lpInfo), typeof(ServiceDescription));
                    }
                }
            }
        }
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     foreach (var channelDispatcherBase in serviceHostBase.ChannelDispatchers)
     {
         var channelDispatcher = channelDispatcherBase as ChannelDispatcher;
         channelDispatcher.ErrorHandlers.Add(new LoggingServiceBehavior());
     }
 }
        /// <summary>
        /// Creates a new <see cref="ServiceClient"/> from the specified description and repository
        /// </summary>
        /// <param name="service">A <see cref="ServiceDescription"/> object that describes the target service</param>
        /// <param name="repository">The <see cref="NuGetRepository"/> object that contains the service</param>
        public ServiceClient(ServiceDescription service, NuGetRepository repository)
        {
            Guard.NotNull(service, "service");
            Guard.NotNull(repository, "repository");

            Service = service;
            Repository = repository;
        }
        public WindowsServiceHost([NotNull] ServiceDescription description, [NotNull] IServiceCoordinator coordinator)
        {
            if (description == null)
                throw new ArgumentNullException("description");
            if (coordinator == null)
                throw new ArgumentNullException("coordinator");

            _coordinator = coordinator;
            _description = description;
        }
Exemple #8
0
 // Registers a service on behalf of an agent
 public static void RegisterService(string serviceName, Agent myAgent)
 {
     DFAgentDescription dfd = new DFAgentDescription();
     dfd.setName(myAgent.getAID());
     ServiceDescription sd = new ServiceDescription();
     sd.setType(serviceName);
     sd.setName(serviceName);
     dfd.addServices(sd);
     DFService.register(myAgent, dfd);
 }
 protected AbstractInstallerHost(ServiceDescription description, ServiceStartMode startMode,
     IEnumerable<string> dependencies, Credentials credentials,
     IEnumerable<Action> preActions, IEnumerable<Action> postActions, bool sudo)
 {
     _startMode = startMode;
     _postActions = postActions;
     _preActions = preActions;
     _credentials = credentials;
     _dependencies = dependencies;
     _description = description;
     Sudo = sudo;
 }
Exemple #10
0
        public ConsoleRunHost([NotNull] ServiceDescription description, [NotNull] IServiceCoordinator coordinator, [NotNull]Os osCommands)
        {
            if (description == null)
                throw new ArgumentNullException("description");
            if (coordinator == null)
                throw new ArgumentNullException("coordinator");
            if(osCommands ==null)
                throw new ArgumentNullException("osCommands");

            _description = description;
            _coordinator = coordinator;
            _osCommands = osCommands;
        }
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        Type serviceType = serviceDescription.ServiceType;
            IInstanceProvider instanceProvider = new NinjectInstanceProvider(serviceType, new StandardKernel(new MyModule()));

            foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
            {
                foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints)
                {
                    DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime;
                    dispatchRuntime.InstanceProvider = instanceProvider;
                }
            }
    }
 public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, ServiceDescription service)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         WsdlExporter exporter = new WsdlExporter();
         string serviceNs = NamingHelper.DefaultNamespace;
         XmlQualifiedName serviceQName = new XmlQualifiedName("comPlusService", serviceNs);
         exporter.ExportEndpoints(service.Endpoints, serviceQName);
         WsdlNS.ServiceDescription wsdl = exporter.GeneratedWsdlDocuments[serviceNs];
         ComPlusServiceHostStartedServiceDetailsSchema record =
             new ComPlusServiceHostStartedServiceDetailsSchema(info.AppID, info.Clsid, wsdl);
         TraceUtility.TraceEvent(type, traceCode, ServiceModelSR.GetString(description), record);
     }
 }
 public void ApplyDispatchBehavior(ServiceDescription desc, ServiceHostBase host)
 {
     foreach (ChannelDispatcherBase cdb in host.ChannelDispatchers)
     {
         ChannelDispatcher cd = cdb as ChannelDispatcher;
         if (cd != null)
         {
             foreach (EndpointDispatcher ed in cd.Endpoints)
             {
                 ed.DispatchRuntime.InstanceProvider =
                     new StructureMapInstanceProvider(desc.ServiceType);
             }
         }
     }
 }
Exemple #14
0
 public StartHost(ServiceDescription description)
 {
     _wrappedHost = null;
     Description = description;
 }
		internal MessageCollection (ServiceDescription serviceDescription)
			: base (serviceDescription)
		{
		}
Exemple #16
0
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("AddNumbersIn_cs.wsdl");

            // Add the ServiceHttpPost binding.
            Binding myBinding = new Binding();
            myBinding.Name = "ServiceHttpPost";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:ServiceHttpPost");
            myBinding.Type = myXmlQualifiedName;
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            myBinding.Extensions.Add(myHttpBinding);

            // Add the operation name AddNumbers.
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myOperation = new HttpOperationBinding();
            myOperation.Location = "/AddNumbers";
            myOperationBinding.Extensions.Add(myOperation);

            // Add the input binding.
            InputBinding       myInput = new InputBinding();
            MimeContentBinding postMimeContentbinding =
                new MimeContentBinding();
            postMimeContentbinding.Type = "application/x-www-form-urlencoded";
            myInput.Extensions.Add(postMimeContentbinding);

            // Add the InputBinding to the OperationBinding.
            myOperationBinding.Input = myInput;

            // Add the ouput binding.
            OutputBinding  myOutput           = new OutputBinding();
            MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();
            postMimeXmlbinding.Part = "Body";
            myOutput.Extensions.Add(postMimeXmlbinding);

            // Add the OutPutBinding to the OperationBinding.
            myOperationBinding.Output = myOutput;

            myBinding.Operations.Add(myOperationBinding);
            myDescription.Bindings.Add(myBinding);

            // Add the port definition.
            Port postPort = new Port();
            postPort.Name    = "ServiceHttpPost";
            postPort.Binding = new XmlQualifiedName("s0:ServiceHttpPost");
            HttpAddressBinding postAddressBinding = new HttpAddressBinding();
            postAddressBinding.Location = "http://localhost/Service_cs.asmx";
            postPort.Extensions.Add(postAddressBinding);
            myDescription.Services[0].Ports.Add(postPort);

            // Add the post port type definition.
            PortType postPortType = new PortType();
            postPortType.Name = "ServiceHttpPost";
            Operation postOperation = new Operation();
            postOperation.Name = "AddNumbers";
            OperationMessage postInput =
                (OperationMessage) new OperationInput();
            postInput.Message =
                new XmlQualifiedName("s0:AddNumbersHttpPostIn");
            OperationOutput postOutput = new OperationOutput();
            postOutput.Message =
                new XmlQualifiedName("s0:AddNumbersHttpPostOut");

            postOperation.Messages.Add(postInput);
            postOperation.Messages.Add(postOutput);
            postPortType.Operations.Add(postOperation);
            myDescription.PortTypes.Add(postPortType);

            // Add the first message information.
            Message postMessage1 = new Message();
            postMessage1.Name = "AddNumbersHttpPostIn";
            MessagePart postMessagePart1 = new MessagePart();
            postMessagePart1.Name = "firstnumber";
            postMessagePart1.Type = new XmlQualifiedName("s:string");

            // Add the second message information.
            MessagePart postMessagePart2 = new MessagePart();
            postMessagePart2.Name = "secondnumber";
            postMessagePart2.Type = new XmlQualifiedName("s:string");
            postMessage1.Parts.Add(postMessagePart1);
            postMessage1.Parts.Add(postMessagePart2);
            Message postMessage2 = new Message();
            postMessage2.Name = "AddNumbersHttpPostOut";

            // Add the third message information.
            MessagePart postMessagePart3 = new MessagePart();
            postMessagePart3.Name    = "Body";
            postMessagePart3.Element = new XmlQualifiedName("s0:int");
            postMessage2.Parts.Add(postMessagePart3);

            myDescription.Messages.Add(postMessage1);
            myDescription.Messages.Add(postMessage2);

            // Write the ServiceDescription as a WSDL file.
            myDescription.Write("AddNumbersOut_cs.wsdl");
            Console.WriteLine("WSDL file named AddNumbersOut_cs.Wsdl" +
                              " created successfully.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
 }
Exemple #18
0
 public StartService(ServiceDescription serviceDescription, Action beforeRequest = null, Action <string> afterRequest = null)
     : base(new ArcGISServerAdminEndpoint(string.Format(Operations.StartService, serviceDescription.Name, serviceDescription.Type)), beforeRequest, afterRequest)
 {
 }
        public void ConfigureService(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            if (ConfigHelper.IsSecurityEnabled(serviceHostBase))
            {
                // Get certificate location from the cert store.
                StoreLocation location = StoreLocation.LocalMachine;
                CertHelper.TryGetCertLocation(ServiceCert, out location, true);

                // Set certificate

                serviceHostBase.Credentials.ServiceCertificate.SetCertificate(
                    location,
                    System.Security.Cryptography.X509Certificates.StoreName.My,
                    X509FindType.FindBySubjectName,
                    ServiceCert);

                // Set certificate validation mode (defaults to peer trust).
                serviceHostBase.Credentials.ClientCertificate.Authentication.CertificateValidationMode = ValidationMode;

                if (serviceHostBase.Description.Endpoints != null)
                {
                    bool reConfigure = false;
                    foreach (var endpoint in serviceHostBase.Description.Endpoints)
                    {
                        if (endpoint.Binding is WS2007HttpBinding)
                        {
                            // Setup each endpoint to use Message security.
                            var binding = endpoint.Binding as WS2007HttpBinding;
                            binding.Security.Mode = SecurityMode.Message;
                            binding.Security.Message.ClientCredentialType       = MessageCredentialType.Certificate;
                            binding.Security.Message.EstablishSecurityContext   = false;
                            binding.Security.Message.NegotiateServiceCredential = false;
                            MaxSetter.SetMaxes(binding);
                        }
                        if (endpoint.Binding is NetTcpBinding)
                        {
                            // Setup each endpoint to use Message security.
                            var binding = endpoint.Binding as NetTcpBinding;
                            binding.Security.Mode = SecurityMode.Message;
                            binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
                            MaxSetter.SetMaxes(binding);
                        }
                        if (endpoint.Binding is BasicHttpBinding)
                        {
                            reConfigure = true;
                        }
                    }

                    // reconfigure host
                    if (reConfigure && serviceHostBase.Description.Endpoints.Count() > 0)
                    {
                        var host = (serviceHostBase as ServiceHost);
                        if (host != null)
                        {
                            // Don't use this crappy binding
                            var address  = serviceHostBase.Description.Endpoints.First().Address;
                            var contract = serviceHostBase.Description.Endpoints.First().Contract;

                            // clear existing
                            host.Description.Endpoints.Clear();

                            var binding = new WS2007HttpBinding();
                            binding.Security.Mode = SecurityMode.Message;
                            binding.Security.Message.ClientCredentialType     = MessageCredentialType.Certificate;
                            binding.Security.Message.EstablishSecurityContext = false;

                            MaxSetter.SetMaxes(binding);

                            var endpoint = host.AddServiceEndpoint(contract.ContractType, binding, address.Uri);
                        }
                    }

                    DisableErrorMasking.Disable(serviceHostBase);
                }
            }
        }
Exemple #20
0
    public static void Main()
    {
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("MimePartCollection_8_Input_cs.wsdl");
        ServiceDescriptionCollection myServiceDescriptionCol =
            new ServiceDescriptionCollection();

        myServiceDescriptionCol.Add(myServiceDescription);
        XmlQualifiedName myXmlQualifiedName =
            new XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/");
        // Create a binding object.
        Binding          myBinding          = myServiceDescriptionCol.GetBinding(myXmlQualifiedName);
        OperationBinding myOperationBinding = null;

        for (int i = 0; i < myBinding.Operations.Count; i++)
        {
            if (myBinding.Operations[i].Name.Equals("AddNumbers"))
            {
                myOperationBinding = myBinding.Operations[i];
            }
        }
        OutputBinding myOutputBinding = myOperationBinding.Output;
// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
        MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null;
        IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator();

        while (myIEnumerator.MoveNext())
        {
            myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding)myIEnumerator.Current;
        }
        // Create an instance of 'MimePartCollection'.
        MimePartCollection myMimePartCollection = new MimePartCollection();

        myMimePartCollection = myMimeMultipartRelatedBinding.Parts;
        Console.WriteLine("Total number of mimepart elements in the collection initially" +
                          " is: " + myMimePartCollection.Count);
        // Get the type of first 'Item' in collection.
        Console.WriteLine("The first object in collection is of type: "
                          + myMimePartCollection[0].ToString());
        MimePart myMimePart1 = new MimePart();
        // Create an instance of 'MimeXmlBinding'.
        MimeXmlBinding myMimeXmlBinding1 = new MimeXmlBinding();

        myMimeXmlBinding1.Part = "body";
        myMimePart1.Extensions.Add(myMimeXmlBinding1);
        //  a mimepart at first position.
        myMimePartCollection.Insert(0, myMimePart1);
        Console.WriteLine("Inserting a mimepart object...");
        // Check whether 'Insert' was successful or not.
        if (myMimePartCollection.Contains(myMimePart1))
        {
            // Display the index of inserted 'MimePart'.
            Console.WriteLine("'MimePart' is successfully inserted at position: "
                              + myMimePartCollection.IndexOf(myMimePart1));
        }
// </Snippet4>
// </Snippet3>
// </Snippet2>
// </Snippet1>
        Console.WriteLine("Total number of mimepart elements after inserting is: "
                          + myMimePartCollection.Count);

// <Snippet5>
// <Snippet6>
        MimePart       myMimePart2       = new MimePart();
        MimeXmlBinding myMimeXmlBinding2 = new MimeXmlBinding();

        myMimeXmlBinding2.Part = "body";
        myMimePart2.Extensions.Add(myMimeXmlBinding2);
        // Add a mimepart to the mimepartcollection.
        myMimePartCollection.Add(myMimePart2);
        Console.WriteLine("Adding a mimepart object...");
        // Check if collection contains added mimepart object.
        if (myMimePartCollection.Contains(myMimePart2))
        {
            Console.WriteLine("'MimePart' is successfully added at position: "
                              + myMimePartCollection.IndexOf(myMimePart2));
        }
// </Snippet6>
// </Snippet5>
        Console.WriteLine("Total number of mimepart elements after adding is: "
                          + myMimePartCollection.Count);

// <Snippet7>
        MimePart[] myArray = new MimePart[myMimePartCollection.Count];
        // Copy the mimepartcollection to an array.
        myMimePartCollection.CopyTo(myArray, 0);
        Console.WriteLine("Displaying the array copied from mimepartcollection");
        for (int j = 0; j < myMimePartCollection.Count; j++)
        {
            Console.WriteLine("Mimepart object at position : " + j);
            for (int i = 0; i < myArray[j].Extensions.Count; i++)
            {
                MimeXmlBinding myMimeXmlBinding3 = (MimeXmlBinding)myArray[j].Extensions[i];
                Console.WriteLine("Part: " + (myMimeXmlBinding3.Part));
            }
        }
// </Snippet7>
// <Snippet8>
        Console.WriteLine("Removing a mimepart object...");
        // Remove the mimepart from the mimepartcollection.
        myMimePartCollection.Remove(myMimePart1);
        // Check whether the mimepart is removed or not.
        if (!myMimePartCollection.Contains(myMimePart1))
        {
            Console.WriteLine("Mimepart is successfully removed from mimepartcollection");
        }
// </Snippet8>
        Console.WriteLine("Total number of elements in collection after removing is: "
                          + myMimePartCollection.Count);
        MimePart[] myArray1 = new MimePart[myMimePartCollection.Count];
        myMimePartCollection.CopyTo(myArray1, 0);
        Console.WriteLine("Dispalying the 'MimePartCollection' after removing");
        for (int j = 0; j < myMimePartCollection.Count; j++)
        {
            Console.WriteLine("Mimepart object at position :" + j);
            for (int i = 0; i < myArray1[j].Extensions.Count; i++)
            {
                MimeXmlBinding myMimeXmlBinding3 = (MimeXmlBinding)myArray1[j].Extensions[i];
                Console.WriteLine("part:  " + (myMimeXmlBinding3.Part));
            }
        }
        myServiceDescription.Write("MimePartCollection_8_output.wsdl");
        Console.WriteLine("MimePartCollection_8_output.wsdl has been generated successfully.");
    }
        static void Main(string[] args)
        {
            //Check Folders
            GridProteinFolding.WCF.ServiceDistributed.Service.CheckWorkFolders();

            //Run Hosts
            ServiceHost hostService           = new ServiceHost(typeof(Service));
            ServiceHost hostDocumentManagment = new ServiceHost(typeof(DocumentManagment));

            //ServiceHost hostGeneratingResults = new ServiceHost(typeof(GeneratingResults));


            try
            {
                #region hostService
                hostService.Open();
                ServiceDescription serviceDesciption = hostService.Description;

                foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                {
                    ConsoleColor oldColour = Console.ForegroundColor;
                    GICO.ForegroundColor(ConsoleColor.Red);
                    GICO.WriteLine(ExtendedString.Format("Endpoint - address:  {0}", endpoint.Address));
                    GICO.WriteLine(ExtendedString.Format("         - binding name:\t\t{0}", endpoint.Binding.Name));
                    GICO.WriteLine(ExtendedString.Format("         - contract name:\t\t{0}", endpoint.Contract.Name));
                    GICO.ForegroundColor(oldColour);
                }
                #endregion

                #region hostDocumentManagment
                hostDocumentManagment.Open();
                serviceDesciption = hostDocumentManagment.Description;

                foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                {
                    ConsoleColor oldColour = Console.ForegroundColor;
                    GICO.ForegroundColor(ConsoleColor.Red);
                    GICO.WriteLine(ExtendedString.Format("Endpoint - address:  {0}", endpoint.Address));
                    GICO.WriteLine(ExtendedString.Format("         - binding name:\t\t{0}", endpoint.Binding.Name));
                    GICO.WriteLine(ExtendedString.Format("         - contract name:\t\t{0}", endpoint.Contract.Name));
                    GICO.WriteLine();
                    GICO.ForegroundColor(oldColour);
                }
                #endregion


                //#region hostGeneratingResults
                //hostGeneratingResults.Open();
                //serviceDesciption = hostGeneratingResults.Description;

                //foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                //{
                //    ConsoleColor oldColour = Console.ForegroundColor;
                //    GICO.ForegroundColor(ConsoleColor.Red);
                //    GICO.WriteLine(String.Format("Endpoint - address:  {0}", endpoint.Address));
                //    GICO.WriteLine(String.Format("         - binding name:\t\t{0}", endpoint.Binding.Name));
                //    GICO.WriteLine(String.Format("         - contract name:\t\t{0}", endpoint.Contract.Name));
                //    GICO.WriteLine();
                //    GICO.ForegroundColor(oldColour);
                //}
                //#endregion
                GICO.WriteLine("Service Distributed: Service is up and running!");

                GICO.WriteLine();
                ConsoleKeyInfo key;

                Console.WriteLine("Press the Escape (Esc) key to quit: \n");
                do
                {
                    key = Console.ReadKey();
                } while (key.Key != ConsoleKey.Escape);
            }
            catch (Exception ex)
            {
                GICO.WriteLine(ex.Message.ToString());
                GICO.WriteLine(ex.InnerException.ToString());

                Console.ReadKey();
            }
            finally
            {
                if (hostService.State != CommunicationState.Closed && hostService.State != CommunicationState.Faulted)
                {
                    hostService.Close();
                }

                hostService = null;


                if (hostDocumentManagment.State != CommunicationState.Closed && hostDocumentManagment.State != CommunicationState.Faulted)
                {
                    hostDocumentManagment.Close();
                }

                hostDocumentManagment = null;
            }
        }
 void IServiceBehavior.Validate(ServiceDescription serviceDescription,
                                ServiceHostBase serviceHostBase)
 {
 }
        public void SetUpFixture()
        {
            // Set up the project.
            MSBuildBasedProject project = WebReferenceTestHelper.CreateTestProject("C#");

            project.FileName = "c:\\projects\\test\\foo.csproj";

            // Web references item.
            WebReferencesProjectItem webReferencesItem = new WebReferencesProjectItem(project);

            webReferencesItem.Include = "Web References\\";
            ProjectService.AddProjectItem(project, webReferencesItem);

            // Web reference url.
            WebReferenceUrl webReferenceUrl = new WebReferenceUrl(project);

            webReferenceUrl.Include       = "http://localhost/test.asmx";
            webReferenceUrl.UpdateFromURL = "http://localhost/test.asmx";
            webReferenceUrl.RelPath       = "Web References\\localhost";
            ProjectService.AddProjectItem(project, webReferenceUrl);

            FileProjectItem discoFileItem = new FileProjectItem(project, ItemType.None);

            discoFileItem.Include = "Web References\\localhost\\test.disco";
            ProjectService.AddProjectItem(project, discoFileItem);

            FileProjectItem wsdlFileItem = new FileProjectItem(project, ItemType.None);

            wsdlFileItem.Include = "Web References\\localhost\\test.wsdl";
            ProjectService.AddProjectItem(project, wsdlFileItem);

            // Proxy
            FileProjectItem proxyItem = new FileProjectItem(project, ItemType.Compile);

            proxyItem.Include       = "Web References\\localhost\\Reference.cs";
            proxyItem.DependentUpon = "Reference.map";
            ProjectService.AddProjectItem(project, proxyItem);

            // Reference map.
            FileProjectItem mapItem = new FileProjectItem(project, ItemType.None);

            mapItem.Include = "Web References\\localhost\\Reference.map";
            ProjectService.AddProjectItem(project, mapItem);

            // System.Web.Services reference.
            ReferenceProjectItem webServicesReferenceItem = new ReferenceProjectItem(project, "System.Web.Services");

            ProjectService.AddProjectItem(project, webServicesReferenceItem);

            // Set up the web reference.
            DiscoveryClientProtocol    protocol     = new DiscoveryClientProtocol();
            DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();

            discoveryRef.Url = "http://localhost/new.asmx";
            protocol.References.Add(discoveryRef);

            ContractReference contractRef = new ContractReference();

            contractRef.Url            = "http://localhost/new.asmx?wsdl";
            contractRef.ClientProtocol = new DiscoveryClientProtocol();
            ServiceDescription desc = new ServiceDescription();

            contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
            protocol.References.Add(contractRef);

            WebReferenceTestHelper.InitializeLanguageBindings();

            SD.WebReference webReference = new SD.WebReference(project, "http://localhost/new.asmx", "localhost", "ProxyNamespace", protocol);
            changes = webReference.GetChanges(project);
        }
 void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription,
                                            ServiceHostBase serviceHostBase,
                                            System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints,
                                            System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
 {
 }
Exemple #25
0
 public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     throw new NotImplementedException();
 }
Exemple #26
0
 public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
 {
     throw new NotImplementedException();
 }
        void SetRecoveryOptions(ServiceDescription description)
        {
            _log.DebugFormat("Setting service recovery options for {0}", description.GetServiceName());

            try
            {
                WindowsServiceControlManager.SetServiceRecoveryOptions(description.GetServiceName(), _options);
            }
            catch (Exception ex)
            {
                _log.Error("Failed to set service recovery options", ex);
            }
        }
Exemple #28
0
        public static object InvokeWebService(string url, string classname, string methodname)
        {
            string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";

            if ((classname == null) || (classname == ""))
            {
                classname = WebServiceHelper.GetWsClassName(url);
            }

            try
            {
                //获取WSDL
                WebClient                  wc     = new WebClient();
                Stream                     stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription         sd     = ServiceDescription.Read(stream);
                ServiceDescriptionImporter sdi    = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                CodeNamespace cn = new CodeNamespace(@namespace);

                //生成客户端代理类代码
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);
                CSharpCodeProvider csc = new CSharpCodeProvider();
                ICodeCompiler      icc = csc.CreateCompiler();

                //设定编译参数
                CompilerParameters cplist = new CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory   = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");

                //编译代理类
                CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }

                //生成代理实例,并调用方法
                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type   t   = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);
                System.Reflection.MethodInfo mi = t.GetMethod(methodname);
                wc.Dispose();
                stream.Close();
                stream.Dispose();

                return(mi.Invoke(obj, null));
            }
            catch (Exception ex)
            {
                return(null);
                //throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
            }
        }
Exemple #29
0
 public void CheckToSeeIfServiceRunning(ServiceDescription description)
 {
     if (ServiceController.GetServices().Where(s => s.ServiceName == description.GetServiceName()).Any())
         _log.WarnFormat("There is an instance of this {0} running as a windows service", description);
 }
Exemple #30
0
 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemple #31
0
 public StopHost(ServiceDescription description)
 {
     Description = description;
 }
Exemple #32
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemple #33
0
 public void ShouldFailIfApiAttributeIsAbsent()
 {
     Assert.Throws <ApiContractException>(() => ServiceDescription.Create(typeof(IContractWithoutApiAttr)));
 }
Exemple #34
0
 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 void IServiceBehavior.AddBindingParameters(ServiceDescription description,
                                            ServiceHostBase serviceHostBase,
                                            Collection <ServiceEndpoint> endpoints, BindingParameterCollection parameters)
 {
 }
Exemple #36
0
 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
 }
 public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
 }
Exemple #38
0
 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection <ServiceEndpoint> endpoints,
                                  BindingParameterCollection bindingParameters)
 {
 }
Exemple #39
0
 public StartHost(ServiceDescription description, Host wrappedHost)
 {
     _wrappedHost = wrappedHost;
     Description = description;
 }
Exemple #40
0
 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) =>
 _behavior.Validate(serviceDescription, serviceHostBase);
 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
                                  Collection <ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
 {
     AutomapperConfiguration.Load();
 }
Exemple #42
0
 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
                                  Collection <ServiceEndpoint> endpoints,
                                  BindingParameterCollection bindingParameters) =>
 _behavior.AddBindingParameters(serviceDescription, serviceHostBase, endpoints, bindingParameters);
Exemple #43
0
        private bool TryCreateServiceDescription(out ServiceDescription sd)
        {
            sd = null;
            bool result = false;

            if (this.Control.Package.Data.ContainsKey("ServiceStateless"))
            {
                StatelessServiceDescription ssd;
                result = this.TryCreateStatelessServiceDescription(out ssd);
                sd = ssd;
            }

            if (this.Control.Package.Data.ContainsKey("ServiceStateful"))
            {
                StatefulServiceDescription ssd;
                result = this.TryCreateStatefulServiceDescription(out ssd);
                sd = ssd;
            }

            return result;
        }
Exemple #44
0
		internal BindingCollection (ServiceDescription serviceDescription) 
			: base (serviceDescription)
		{
		}
Exemple #45
0
 public void CheckToSeeIfServiceRunning(ServiceDescription description)
 {
     _log.Warn("Nix not detecting, maybe check the pid?");
 }
Exemple #46
0
        public CodeGenerationResults Generate(IArtifactLink link)
        {
            CodeGenerationResults result           = new CodeGenerationResults();
            string       serviceImplementationName = string.Empty;
            string       serviceContractName       = string.Empty;
            string       serviceNamespace          = string.Empty;
            const string behavior = "_Behavior";

            if (link is IModelReference)
            {
                this.serviceProvider = Utility.GetData <IServiceProvider>(link);
                ProjectNode project = Utility.GetData <ProjectNode>(link);

                ServiceDescription serviceDescription = ((IModelReference)link).ModelElement as ServiceDescription;
                Configuration      configuration      = GetConfiguration(link, project);

                // abort if we got errors in config file
                if (configuration == null)
                {
                    return(result);
                }

                try
                {
                    ServiceReference serviceReference = (ServiceReference)serviceDescription;
                    SCModel.Service  service          = GetMelReference <SCModel.Service>(serviceReference.ServiceImplementationType);
                    serviceImplementationName = ResolveTypeReference(service);
                    serviceContractName       = GetServiceContractName(service.ServiceContract);
                    serviceNamespace          = service.ServiceContract.Namespace;

                    ServiceModelConfigurationManager manager = new ServiceModelConfigurationManager(configuration);

                    ServiceElement serviceElement = new ServiceElement();
                    serviceElement.Name = serviceImplementationName;
                    serviceElement.BehaviorConfiguration = string.Concat(serviceImplementationName, behavior);

                    foreach (Endpoint endpoint in serviceDescription.Endpoints)
                    {
                        ServiceEndpointElement endpointElement = new ServiceEndpointElement();
                        endpointElement.Name             = endpoint.Name;
                        endpointElement.Contract         = serviceContractName;
                        endpointElement.Binding          = ((WcfEndpoint)endpoint.ObjectExtender).BindingType.ToString();
                        endpointElement.Address          = new Uri(endpoint.Address ?? string.Empty, UriKind.RelativeOrAbsolute);
                        endpointElement.BindingNamespace = serviceNamespace;
                        serviceElement.Endpoints.Add(endpointElement);
                    }

                    manager.UpdateService(serviceElement);

                    ServiceBehaviorElement behaviorElement = new ServiceBehaviorElement();
                    behaviorElement.Name = string.Concat(serviceImplementationName, behavior);
                    ServiceDebugElement debugElement = new ServiceDebugElement();
                    debugElement.IncludeExceptionDetailInFaults = false;
                    behaviorElement.Add(debugElement);

                    if (((WcfServiceDescription)serviceDescription.ObjectExtender).EnableMetadataPublishing)
                    {
                        ServiceMetadataPublishingElement metadataPublishingElement = new ServiceMetadataPublishingElement();
                        metadataPublishingElement.HttpGetEnabled = true;
                        behaviorElement.Add(metadataPublishingElement);
                        ServiceEndpointElement mexEndpointElement = ServiceModelConfigurationManager.GetMetadataExchangeEndpoint();
                        serviceElement.Endpoints.Add(mexEndpointElement);
                    }

                    manager.UpdateBehavior(behaviorElement);
                    manager.Save();

                    result.Add(link.ItemPath, File.ReadAllText(configuration.FilePath));
                }
                finally
                {
                    if (configuration != null && File.Exists(configuration.FilePath))
                    {
                        File.Delete(configuration.FilePath);
                    }
                }
            }

            return(result);
        }
Exemple #47
0
 public InstallHost(ServiceDescription description, ServiceStartMode startMode, IEnumerable<string> dependencies,
     Credentials credentials, IEnumerable<Action> preActions, IEnumerable<Action> postActions, bool sudo)
     : base(description, startMode, dependencies, credentials, preActions, postActions, sudo)
 {
 }
 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
 {
 }
Exemple #49
0
 public ConsoleRunHost(ServiceDescription description, IServiceCoordinator coordinator)
 {
     _description = description;
     _coordinator = coordinator;
 }
 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
 }
 static HostBuilder DefaultBuilderFactory(ServiceDescription description)
 {
     return new RunBuilder(description);
 }
Exemple #52
0
 public ServiceImplementationInfo(ServiceDescription description, object implementation)
 {
     Description    = description;
     Implementation = implementation;
 }
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
     {
         channelDispatcher.ErrorHandlers.Add(new MyErrorHandler());
     }
 }
Exemple #54
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     _state.CurrentStage += ", IServiceBehavior.ApplyDispatchBehavior";
 }
Exemple #55
0
 public HostInstaller(ServiceDescription description, string arguments, Installer[] installers)
 {
     _installers = installers;
     _arguments = arguments;
     _description = description;
 }
Exemple #56
0
 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, global::System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
 {
     _state.CurrentStage += ", IServiceBehavior.AddBindingParameters";
     bindingParameters.Add(this);
 }
Exemple #57
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) =>
 _behavior.ApplyDispatchBehavior(serviceDescription, serviceHostBase);
Exemple #58
0
 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     _state.CurrentStage += ", IServiceBehavior.Validate";
     Assert.AreEqual(_host.ChannelDispatchers.Count, 0);
 }
Exemple #59
0
 public TopshelfDashboard(ServiceDescription description, IServiceChannel serviceCoordinator)
 {
     _description = description;
     _serviceCoordinator = serviceCoordinator;
     _port = 8483;
 }
Exemple #60
0
 void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
 {
 }