private void SetExtensionProperties(ServiceMetadataExtension mex, ServiceHostBase host)
 {
     mex.HttpHelpPageEnabled = this.httpHelpPageEnabled;
     mex.HttpHelpPageUrl = host.GetVia(Uri.UriSchemeHttp, (this.httpHelpPageUrl == null) ? new Uri(string.Empty, UriKind.Relative) : this.httpHelpPageUrl);
     mex.HttpHelpPageBinding = this.HttpHelpPageBinding;
     mex.HttpsHelpPageEnabled = this.httpsHelpPageEnabled;
     mex.HttpsHelpPageUrl = host.GetVia(Uri.UriSchemeHttps, (this.httpsHelpPageUrl == null) ? new Uri(string.Empty, UriKind.Relative) : this.httpsHelpPageUrl);
     mex.HttpsHelpPageBinding = this.HttpsHelpPageBinding;
 }
 private bool EnsureHelpPageDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme)
 {
     Uri via = host.GetVia(scheme, (url == null) ? new Uri(string.Empty, UriKind.Relative) : url);
     if (via == null)
     {
         return false;
     }
     ((ServiceMetadataExtension.HttpGetImpl) mex.EnsureGetDispatcher(via, 1).Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).HelpPageEnabled = true;
     return true;
 }
 private void CreateHttpGetEndpoints(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
 {
     if (this.httpGetEnabled)
     {
         EnsureGetDispatcher(host, mex, this.httpGetUrl, Uri.UriSchemeHttp);
     }
     if (this.httpsGetEnabled)
     {
         EnsureGetDispatcher(host, mex, this.httpsGetUrl, Uri.UriSchemeHttps);
     }
 }
 private void CreateHelpPageEndpoints(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
 {
     if (this.httpHelpPageEnabled && !this.EnsureHelpPageDispatcher(host, mex, this.httpHelpPageUrl, Uri.UriSchemeHttp))
     {
         TraceWarning(this.httpHelpPageUrl, "ServiceDebugBehaviorHttpHelpPageUrl", "ServiceDebugBehaviorHttpHelpPageEnabled");
     }
     if (this.httpsHelpPageEnabled && !this.EnsureHelpPageDispatcher(host, mex, this.httpsHelpPageUrl, Uri.UriSchemeHttps))
     {
         TraceWarning(this.httpHelpPageUrl, "ServiceDebugBehaviorHttpsHelpPageUrl", "ServiceDebugBehaviorHttpsHelpPageEnabled");
     }
 }
        public void ServiceMetadataExtension2()
        {
            using (ServiceHost host = new ServiceHost(typeof(MyService), CreateUri("http://localhost:37564"))) {
                host.AddServiceEndpoint(typeof(IMyContract), new BasicHttpBinding(), "");
                host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageUrl = CreateUri("http://localhost:37564/help");

                ServiceMetadataExtension extension = new ServiceMetadataExtension();
                host.Extensions.Add(extension);

                host.Open();

                Assert.IsNotNull(host.Extensions.Find <ServiceMetadataExtension> (), "ServiceMetadataExtension #1");
                Assert.AreEqual(1, host.Extensions.FindAll <ServiceMetadataExtension> ().Count, "ServiceMetadataExtension #2");
                Assert.AreEqual(extension, host.Extensions.Find <ServiceMetadataExtension> (), "ServiceMetadataExtension #3");

                host.Close();
            }
        }
 private static void CustomizeMetadataEndpoints(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
 {
     for (int i = 0; i < host.ChannelDispatchers.Count; i++)
     {
         ChannelDispatcher channelDispatcher = host.ChannelDispatchers[i] as ChannelDispatcher;
         if ((channelDispatcher != null) && IsMetadataTransferDispatcher(description, channelDispatcher))
         {
             if (channelDispatcher.Endpoints.Count != 1)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxServiceMetadataBehaviorInstancingError", new object[] { channelDispatcher.Listener.Uri, channelDispatcher.CreateContractListString() })));
             }
             DispatchRuntime dispatchRuntime = channelDispatcher.Endpoints[0].DispatchRuntime;
             dispatchRuntime.InstanceContextProvider = InstanceContextProviderBase.GetProviderForMode(InstanceContextMode.Single, dispatchRuntime);
             bool isListeningOnHttps = channelDispatcher.Listener.Uri.Scheme == Uri.UriSchemeHttps;
             Uri listenUri = channelDispatcher.Listener.Uri;
             ServiceMetadataExtension.WSMexImpl implementation = new ServiceMetadataExtension.WSMexImpl(mex, isListeningOnHttps, listenUri);
             dispatchRuntime.SingletonInstanceContext = new InstanceContext(host, implementation, false);
         }
     }
 }
        public void ServiceMetadataExtension2()
        {
            int port = NetworkHelpers.FindFreePort();

            using (ServiceHost host = new ServiceHost(typeof(MyService), new Uri("http://localhost:" + port))) {
                host.AddServiceEndpoint(typeof(IMyContract), new BasicHttpBinding(), "");
                host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageUrl = new Uri("http://localhost:" + port + "/help");

                ServiceMetadataExtension extension = new ServiceMetadataExtension();
                host.Extensions.Add(extension);

                try {
                    host.Open();

                    Assert.IsNotNull(host.Extensions.Find <ServiceMetadataExtension> (), "ServiceMetadataExtension #1");
                    Assert.AreEqual(1, host.Extensions.FindAll <ServiceMetadataExtension> ().Count, "ServiceMetadataExtension #2");
                    Assert.AreEqual(extension, host.Extensions.Find <ServiceMetadataExtension> (), "ServiceMetadataExtension #3");
                } finally {
                    host.Close();
                }
            }
        }
        public void ServiceMetadataExtension2()
        {
            using (ServiceHost host = new ServiceHost(typeof(MyService), new Uri("http://localhost:8080"))) {
                host.AddServiceEndpoint(typeof(IMyContract), new BasicHttpBinding(), "");
                host.Description.Behaviors.Add(new ServiceMetadataBehavior()
                {
                    HttpGetEnabled = true, HttpGetUrl = new Uri("http://localhost:8080/mex")
                });
                host.Description.Behaviors.Remove <ServiceDebugBehavior> ();

                ServiceMetadataExtension extension = new ServiceMetadataExtension();
                host.Extensions.Add(extension);

                host.Open();

                Assert.IsNotNull(host.Extensions.Find <ServiceMetadataExtension> (), "ServiceMetadataExtension #1");
                Assert.AreEqual(1, host.Extensions.FindAll <ServiceMetadataExtension> ().Count, "ServiceMetadataExtension #2");
                Assert.AreEqual(extension, host.Extensions.Find <ServiceMetadataExtension> (), "ServiceMetadataExtension #3");

                host.Close();
            }
        }
		public void ServiceMetadataExtension2 () {
			var port = NetworkHelpers.FindFreePort ();
			using (ServiceHost host = new ServiceHost (typeof (MyService), new Uri ("http://localhost:" + port))) {
				host.AddServiceEndpoint (typeof (IMyContract), new BasicHttpBinding (), "");
				host.Description.Behaviors.Add (new ServiceMetadataBehavior () { HttpGetEnabled = true, HttpGetUrl = new Uri ("http://localhost:" + port + "/mex") });
				host.Description.Behaviors.Remove<ServiceDebugBehavior> ();

				ServiceMetadataExtension extension = new ServiceMetadataExtension ();
				host.Extensions.Add (extension);

				host.Open ();

				Assert.IsNotNull (host.Extensions.Find<ServiceMetadataExtension> (), "ServiceMetadataExtension #1");
				Assert.AreEqual (1, host.Extensions.FindAll<ServiceMetadataExtension> ().Count, "ServiceMetadataExtension #2");
				Assert.AreEqual (extension, host.Extensions.Find<ServiceMetadataExtension> (), "ServiceMetadataExtension #3");

				host.Close ();
			}
		}
		public void ServiceMetadataExtension2 () {
			int port = NetworkHelpers.FindFreePort ();
			using (ServiceHost host = new ServiceHost (typeof (MyService), new Uri ("http://localhost:" + port))) {
				host.AddServiceEndpoint (typeof (IMyContract), new BasicHttpBinding (), "");
				host.Description.Behaviors.Find<ServiceDebugBehavior> ().HttpHelpPageUrl = new Uri ("http://localhost:" + port + "/help");

				ServiceMetadataExtension extension = new ServiceMetadataExtension ();
				host.Extensions.Add (extension);

				try {
				host.Open ();

				Assert.IsNotNull (host.Extensions.Find<ServiceMetadataExtension> (), "ServiceMetadataExtension #1");
				Assert.AreEqual (1, host.Extensions.FindAll<ServiceMetadataExtension> ().Count, "ServiceMetadataExtension #2");
				Assert.AreEqual (extension, host.Extensions.Find<ServiceMetadataExtension> (), "ServiceMetadataExtension #3");
				} finally {
				host.Close ();
				}
			}
		}
        bool EnsureHelpPageDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme)
        {
            Uri address = host.GetVia(scheme, url == null ? new Uri(string.Empty, UriKind.Relative) : url);

            if (address == null)
            {
                return false;
            }

            ChannelDispatcher channelDispatcher = mex.EnsureGetDispatcher(address, true /* isServiceDebugBehavior */);
            ((ServiceMetadataExtension.HttpGetImpl)channelDispatcher.Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).HelpPageEnabled = true;

            return true;
        }
        void SetExtensionProperties(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
        {
            mex.ExternalMetadataLocation = this.ExternalMetadataLocation;
            mex.Initializer = new MetadataExtensionInitializer(this, description, host);
            mex.HttpGetEnabled = this.httpGetEnabled;
            mex.HttpsGetEnabled = this.httpsGetEnabled;

            mex.HttpGetUrl = host.GetVia(Uri.UriSchemeHttp, this.httpGetUrl == null ? new Uri(string.Empty, UriKind.Relative) : this.httpGetUrl);
            mex.HttpsGetUrl = host.GetVia(Uri.UriSchemeHttps, this.httpsGetUrl == null ? new Uri(string.Empty, UriKind.Relative) : this.httpsGetUrl);

            mex.HttpGetBinding = this.httpGetBinding;
            mex.HttpsGetBinding = this.httpsGetBinding;

            UseRequestHeadersForMetadataAddressBehavior dynamicUpdateBehavior = description.Behaviors.Find<UseRequestHeadersForMetadataAddressBehavior>();
            if (dynamicUpdateBehavior != null)
            {
                mex.UpdateAddressDynamically = true;
                mex.UpdatePortsByScheme = new Dictionary<string, int>(dynamicUpdateBehavior.DefaultPortsByScheme);
            }

            foreach (ChannelDispatcherBase dispatcherBase in host.ChannelDispatchers)
            {
                ChannelDispatcher dispatcher = dispatcherBase as ChannelDispatcher;
                if (dispatcher != null && IsMetadataTransferDispatcher(description, dispatcher))
                {
                    mex.MexEnabled = true;
                    mex.MexUrl = dispatcher.Listener.Uri;
                    if (dynamicUpdateBehavior != null)
                    {
                        foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints)
                        {
                            if (!endpointDispatcher.AddressFilterSetExplicit)
                            {
                                endpointDispatcher.AddressFilter = new MatchAllMessageFilter();
                            }
                        }
                    }
                    break;
                }
            }

        }
        private void CreateHttpGetEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
        {
            bool httpDispatcherEnabled = false;
            bool httpsDispatcherEnabled = false;

            if (this.httpGetEnabled)
            {
                httpDispatcherEnabled = EnsureGetDispatcher(host, mex, this.httpGetUrl, Uri.UriSchemeHttp);
            }

            if (this.httpsGetEnabled)
            {
                httpsDispatcherEnabled = EnsureGetDispatcher(host, mex, this.httpsGetUrl, Uri.UriSchemeHttps);
            }

            if (!httpDispatcherEnabled && !httpsDispatcherEnabled)
            {
                if (this.httpGetEnabled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceMetadataBehaviorNoHttpBaseAddress)));
                }

                if (this.httpsGetEnabled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceMetadataBehaviorNoHttpsBaseAddress)));
                }
            }
        }
 private static void EnsureGetDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme)
 {
     Uri via = host.GetVia(scheme, (url == null) ? new Uri(string.Empty, UriKind.Relative) : url);
     if (via == null)
     {
         if (scheme == Uri.UriSchemeHttp)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxServiceMetadataBehaviorNoHttpBaseAddress")));
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxServiceMetadataBehaviorNoHttpsBaseAddress")));
     }
     ((ServiceMetadataExtension.HttpGetImpl) mex.EnsureGetDispatcher(via, 0).Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).GetWsdlEnabled = true;
 }