public void CanAddNewEndpoint()
        {
            ServiceEndpointElement           mexEndpoint = ServiceModelConfigurationManager.GetMetadataExchangeEndpoint();
            ServiceModelConfigurationManager manager     = LoadManager();

            manager.AddEndpoint(Constants.ServiceName, mexEndpoint);

            Assert.AreEqual(mexEndpoint,
                            manager.GetEndpoint(Constants.ServiceName, manager.GetEndpointName(mexEndpoint)));
        }
        public void CanGetEndpointNamesWithoutMexEndpoints()
        {
            ServiceEndpointElement           mexEndpoint       = ServiceModelConfigurationManager.GetMetadataExchangeEndpoint();
            ServiceEndpointElement           secureMexEndpoint = ServiceModelConfigurationManager.GetSecureMetadataExchangeEndpoint();
            ServiceModelConfigurationManager manager           = LoadManager();

            manager.AddEndpoint(Constants.ServiceName, mexEndpoint);
            manager.AddEndpoint(Constants.ServiceName, secureMexEndpoint);

            IList <string> endpointNames = manager.GetEndpointNames(Constants.ServiceName);

            Assert.IsFalse(endpointNames.Contains(manager.GetEndpointName(mexEndpoint)));
            Assert.IsFalse(endpointNames.Contains(manager.GetEndpointName(secureMexEndpoint)));
        }
Ejemplo n.º 3
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);
        }