コード例 #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);
            }
        }
コード例 #2
0
        public void ServiceDebugElement_defaults()
        {
            ServiceDebugElement element = new ServiceDebugElement();

            Assert.AreEqual(typeof(ServiceDebugBehavior), element.BehaviorType, "BehaviorType");
            Assert.AreEqual("serviceDebug", element.ConfigurationElementName, "ConfigurationElementName");

            Assert.AreEqual(true, element.HttpHelpPageEnabled, "HttpHelpPageEnabled");
            Assert.AreEqual(null, element.HttpHelpPageUrl, "HttpHelpPageUrl");
            Assert.AreEqual(true, element.HttpsHelpPageEnabled, "HttpsHelpPageEnabled");
            Assert.AreEqual(null, element.HttpsHelpPageUrl, "HttpsHelpPageUrl");
            Assert.AreEqual(false, element.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
        }
コード例 #3
0
        /// <summary>
        /// Checks the specified configuration manager.
        /// </summary>
        /// <param name="configurationManager">The configuration manager.</param>
        /// <returns></returns>
        public override ProblemCollection Check(ServiceModelConfigurationManager configurationManager)
        {
            foreach (ServiceBehaviorElement behaviorElement in configurationManager.ServiceModelSection.Behaviors.ServiceBehaviors)
            {
                ServiceDebugElement serviceDebug =
                    ServiceModelConfigurationManager.GetBehaviorExtensionElement <ServiceDebugElement>(behaviorElement);

                if (serviceDebug.IncludeExceptionDetailInFaults)
                {
                    Resolution resolution = base.GetResolution(behaviorElement.Name);
                    Problem    problem    = new Problem(resolution);
                    problem.SourceFile = base.SourceFile;
                    base.Problems.Add(problem);
                }
            }
            return(base.Problems);
        }
コード例 #4
0
        public void ServiceDebugElement()
        {
            ServiceBehaviorElement behavior = OpenConfig();
            ServiceDebugElement    element  = (ServiceDebugElement)behavior [typeof(ServiceDebugElement)];

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

            Assert.AreEqual(typeof(ServiceDebugBehavior), element.BehaviorType, "BehaviorType");
            Assert.AreEqual("serviceDebug", element.ConfigurationElementName, "ConfigurationElementName");

            Assert.AreEqual(false, element.HttpHelpPageEnabled, "HttpHelpPageEnabled");
            Assert.AreEqual("http://help.page.url", element.HttpHelpPageUrl.OriginalString, "HttpHelpPageUrl");
            Assert.AreEqual(false, element.HttpsHelpPageEnabled, "HttpsHelpPageEnabled");
            Assert.AreEqual("https://help.page.url", element.HttpsHelpPageUrl.OriginalString, "HttpsHelpPageUrl");
            Assert.AreEqual(true, element.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
        }
コード例 #5
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);
        }