public override BindingElementCollection CreateBindingElements() { return(new BindingElementCollection(new BindingElement [] { msgenc, t.Clone() })); }
void AddMetadataEndpoint(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher, bool debugMode) { Uri baseAddress = endpoint.Address.Uri; if (baseAddress == null) { return; } ServiceHostBase host = endpointDispatcher.ChannelDispatcher.Host; UriBuilder builder = new UriBuilder(baseAddress); builder.Path += builder.Path.EndsWith("/", StringComparison.OrdinalIgnoreCase) ? (WebScriptClientGenerator.GetMetadataEndpointSuffix(debugMode)) : ("/" + WebScriptClientGenerator.GetMetadataEndpointSuffix(debugMode)); EndpointAddress metadataAddress = new EndpointAddress(builder.Uri); foreach (ServiceEndpoint serviceEndpoint in host.Description.Endpoints) { if (EndpointAddress.UriEquals(serviceEndpoint.Address.Uri, metadataAddress.Uri, true, false))// ignoreCase // includeHostNameInComparison { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR2.GetString(SR2.JsonNoEndpointAtMetadataAddress, this.GetType().ToString(), serviceEndpoint.Address, serviceEndpoint.Name, host.Description.Name))); } } HttpTransportBindingElement transportBindingElement; HttpTransportBindingElement existingTransportBindingElement = endpoint.Binding.CreateBindingElements().Find <HttpTransportBindingElement>(); if (existingTransportBindingElement != null) { transportBindingElement = (HttpTransportBindingElement)existingTransportBindingElement.Clone(); } else { if (baseAddress.Scheme == "https") { transportBindingElement = new HttpsTransportBindingElement(); } else { transportBindingElement = new HttpTransportBindingElement(); } } transportBindingElement.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; transportBindingElement.TransferMode = TransferMode.Buffered; transportBindingElement.MaxBufferSize = MaxMetadataEndpointBufferSize; transportBindingElement.MaxReceivedMessageSize = MaxMetadataEndpointBufferSize; Binding metadataBinding = new CustomBinding( new WebScriptMetadataMessageEncodingBindingElement(), transportBindingElement); BindingParameterCollection parameters = host.GetBindingParameters(endpoint); // build endpoint dispatcher ContractDescription metadataContract = ContractDescription.GetContract(typeof(ServiceMetadataExtension.IHttpGetMetadata)); OperationDescription metadataOperation = metadataContract.Operations[0]; EndpointDispatcher metadataEndpointDispatcher = new EndpointDispatcher(metadataAddress, metadataContract.Name, metadataContract.Namespace); DispatchOperation dispatchOperation = new DispatchOperation(metadataEndpointDispatcher.DispatchRuntime, metadataOperation.Name, metadataOperation.Messages[0].Action, metadataOperation.Messages[1].Action); dispatchOperation.Formatter = new WebScriptMetadataFormatter(); dispatchOperation.Invoker = new SyncMethodInvoker(metadataOperation.SyncMethod); metadataEndpointDispatcher.DispatchRuntime.Operations.Add(dispatchOperation); metadataEndpointDispatcher.DispatchRuntime.SingletonInstanceContext = new InstanceContext(host, new WebScriptClientGenerator(endpoint, debugMode, !String.IsNullOrEmpty(this.JavascriptCallbackParameterName))); metadataEndpointDispatcher.DispatchRuntime.InstanceContextProvider = new SingletonInstanceContextProvider(metadataEndpointDispatcher.DispatchRuntime); // build channel dispatcher IChannelListener <IReplyChannel> listener = null; if (metadataBinding.CanBuildChannelListener <IReplyChannel>(parameters)) { listener = metadataBinding.BuildChannelListener <IReplyChannel>(metadataAddress.Uri, parameters); } ChannelDispatcher metadataChannelDispatcher = new ChannelDispatcher(listener); metadataChannelDispatcher.MessageVersion = MessageVersion.None; metadataChannelDispatcher.Endpoints.Add(metadataEndpointDispatcher); host.ChannelDispatchers.Add(metadataChannelDispatcher); }