Ejemplo n.º 1
0
        protected void EnsureComMetaDataExchangeBehaviorAdded(Configuration config)
        {
            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);

            if (!sg.Behaviors.ServiceBehaviors.ContainsKey(comServiceBehavior))
            {
                ServiceBehaviorElement behavior = new ServiceBehaviorElement(comServiceBehavior);
                sg.Behaviors.ServiceBehaviors.Add(behavior);
                ServiceMetadataPublishingElement metadataPublishing = new ServiceMetadataPublishingElement();

                if (Tool.Options.Hosting == Hosting.Complus || Tool.Options.Hosting == Hosting.NotSpecified)
                {
                    metadataPublishing.HttpGetEnabled = false;
                }
                else
                {
                    metadataPublishing.HttpGetEnabled = true;
                }
                behavior.Add(metadataPublishing);

                ServiceDebugElement serviceDebug = new ServiceDebugElement();
                serviceDebug.IncludeExceptionDetailInFaults = false;
                behavior.Add(serviceDebug);
            }
        }
Ejemplo n.º 2
0
        public void ServiceMetadataPublishingElement_defaults()
        {
            ServiceMetadataPublishingElement element = new ServiceMetadataPublishingElement();

            Assert.AreEqual(typeof(ServiceMetadataBehavior), element.BehaviorType, "BehaviorType");
            Assert.AreEqual("serviceMetadata", element.ConfigurationElementName, "ConfigurationElementName");

            Assert.AreEqual(false, element.HttpGetEnabled, "HttpGetEnabled");
            Assert.AreEqual(null, element.HttpGetUrl, "HttpGetUrl");
            Assert.AreEqual(false, element.HttpsGetEnabled, "HttpsGetEnabled");
            Assert.AreEqual(null, element.HttpsGetUrl, "HttpsGetUrl");
            Assert.AreEqual(null, element.ExternalMetadataLocation, "ExternalMetadataLocation");
            Assert.AreEqual(PolicyVersion.Default, element.PolicyVersion, "PolicyVersion");
        }
Ejemplo n.º 3
0
        public void ServiceMetadataPublishingElement()
        {
            ServiceBehaviorElement           behavior = OpenConfig();
            ServiceMetadataPublishingElement element  = (ServiceMetadataPublishingElement)behavior [typeof(ServiceMetadataPublishingElement)];

            if (element == null)
            {
                Assert.Fail("ServiceMetadataPublishingElement is not exist in collection.");
            }

            Assert.AreEqual(typeof(ServiceMetadataBehavior), element.BehaviorType, "BehaviorType");
            Assert.AreEqual("serviceMetadata", element.ConfigurationElementName, "ConfigurationElementName");

            Assert.AreEqual(true, element.HttpGetEnabled, "HttpGetEnabled");
            Assert.AreEqual("http://get.url", element.HttpGetUrl.OriginalString, "HttpGetUrl");
            Assert.AreEqual(true, element.HttpsGetEnabled, "HttpsGetEnabled");
            Assert.AreEqual("https://get.url", element.HttpsGetUrl.OriginalString, "HttpsHelpPageUrl");
            Assert.AreEqual("http://external.metadata.location", element.ExternalMetadataLocation.OriginalString, "ExternalMetadataLocation");
            Assert.AreEqual(PolicyVersion.Policy12, element.PolicyVersion, "PolicyVersion");
        }
Ejemplo n.º 4
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);
        }