예제 #1
0
        void ApplyConfiguration(string configurationName)
        {
            WebHttpBindingCollectionElement section = WebHttpBindingCollectionElement.GetBindingCollectionElement();
            WebHttpBindingElement           element = section.Bindings[configurationName];

            if (element == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                              SR2.GetString(SR2.ConfigInvalidBindingConfigurationName,
                                                                                            configurationName,
                                                                                            WebHttpBindingConfigurationStrings.WebHttpBindingCollectionElementName)));
            }
            else
            {
                element.ApplyConfiguration(this);
            }
        }
        protected override void OnOpening()
        {
            WebServiceHost.AddAutomaticWebHttpBindingEndpoints(this, this.ImplementedContracts,
                                                               SR2.GetString(SR2.JsonWebScriptServiceHostOneServiceContract, this.ImplementedContracts.Count),
                                                               SR2.GetString(SR2.JsonWebScriptServiceHostAtLeastOneServiceContract), WebScriptEndpointKind);
            foreach (ServiceEndpoint endpoint in this.Description.Endpoints)
            {
                if (endpoint.Binding != null && endpoint.Binding.CreateBindingElements().Find <WebMessageEncodingBindingElement>() != null)
                {
                    if (endpoint.Behaviors.Find <WebHttpBehavior>() == null)
                    {
                        ConfigLoader.LoadDefaultEndpointBehaviors(endpoint);
                        if (endpoint.Behaviors.Find <WebHttpBehavior>() == null)
                        {
                            endpoint.Behaviors.Add(new WebScriptEnablingBehavior());
                        }
                    }
                }
            }

            base.OnOpening();
        }
예제 #3
0
        public ServiceEndpoint AddServiceEndpoint(Type implementedContract, Binding binding, Uri address, Uri listenUri)
        {
            if (implementedContract == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("implementedContract"));
            }
            if (!implementedContract.IsDefined(typeof(ServiceContractAttribute), false))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ServiceContractAttributeNotFound, new object[] { implementedContract.FullName })));
            }
            if (this.reflectedContracts == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ReflectedContractsNotInitialized, new object[] { implementedContract.FullName })));
            }

            if (!reflectedContracts.Contains(implementedContract))
            {
                if (ServiceMetadataBehavior.IsMetadataImplementedType(implementedContract))
                {
                    if (!this.Description.Behaviors.Contains(
                            typeof(ServiceMetadataBehavior)))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.MetadataEndpointCannotBeAdded, new object[] { implementedContract.FullName })));
                    }
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ReflectedContractKeyNotFound, new object[] { implementedContract.FullName, this.workflowDefinitionContext.WorkflowName })));
                }
            }
            ServiceEndpoint endpoint = base.AddServiceEndpoint(ContractDescription.GetContract(implementedContract).ConfigurationName, binding, address);

            if (listenUri != null)
            {
                listenUri          = base.MakeAbsoluteUri(listenUri, binding);
                endpoint.ListenUri = listenUri;
            }

            return(endpoint);
        }