System.ServiceModel.Description.ContractDescription.GetContract C# (CSharp) Method

GetContract() private method

private GetContract ( Type contractType ) : ContractDescription
contractType System.Type
return ContractDescription
		public static ContractDescription GetContract (
			Type contractType)
		{
			return ContractDescriptionGenerator.GetContract (contractType);
		}

Same methods

ContractDescription::GetContract ( Type contractType, Type serviceType ) : ContractDescription
ContractDescription::GetContract ( Type contractType, object serviceImplementation ) : ContractDescription

Usage Example

示例#1
0
        // FIXME: distinguish HTTP and HTTPS in the Url properties.
        // FIXME: reject such ServiceDescription that has no HTTP(S) binding.
        // FIXME: it should not use the binding that is used in the ServiceEndpoint. For example, WSDL results have to be given as text, not binary.
        // FIXME: if the ServiceDescription has a base address (e.g. http://localhost:8080) and HttpGetUrl is empty, it returns UnknownDestination while it is expected to return the HTTP help page.
        internal void EnsureChannelDispatcher(bool isMex, string scheme, Uri uri, WCFBinding binding)
        {
            if (isMex)
            {
                instance.WsdlUrl = uri;
            }
            else
            {
                instance.HelpUrl = uri;
            }

            if (dispatchers == null)
            {
                dispatchers = new Dictionary <Uri, ChannelDispatcher> ();
            }
            else if (dispatchers.ContainsKey(uri))
            {
                var info = dispatchers [uri].Listener.GetProperty <MetadataPublishingInfo> ();
                if (isMex)
                {
                    info.SupportsMex = true;
                }
                else
                {
                    info.SupportsHelp = true;
                }
                return;
            }

            if (binding == null)
            {
                switch (scheme)
                {
                case "http":
                    binding = MetadataExchangeBindings.CreateMexHttpBinding();
                    break;

                case "https":
                    binding = MetadataExchangeBindings.CreateMexHttpsBinding();
                    break;

                case "net.tcp":
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                    break;

                case "net.pipe":
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    break;
                }
            }

            CustomBinding cb = new CustomBinding(binding)
            {
                Name = ServiceMetadataBehaviorHttpGetBinding
            };

            cb.Elements.Find <MessageEncodingBindingElement> ().MessageVersion = MessageVersion.None;

            ServiceEndpoint se = new ServiceEndpoint(ContractDescription.GetContract(typeof(IHttpGetHelpPageAndMetadataContract)), cb, new EndpointAddress(uri))
            {
                ListenUri = uri,
            };

            var channelDispatcher = new DispatcherBuilder().BuildChannelDispatcher(owner.Description.ServiceType, se, new BindingParameterCollection());
            // add HttpGetWsdl to indicate that the ChannelDispatcher is for mex or help.
            var listener = channelDispatcher.Listener as ChannelListenerBase;

            if (listener != null)
            {
                listener.Properties.Add(new MetadataPublishingInfo()
                {
                    SupportsMex = isMex, SupportsHelp = !isMex, Instance = instance
                });
            }
            channelDispatcher.Endpoints [0].DispatchRuntime.InstanceContextProvider = new SingletonInstanceContextProvider(new InstanceContext(owner, instance));

            dispatchers.Add(uri, channelDispatcher);
            owner.ChannelDispatchers.Add(channelDispatcher);
        }
All Usage Examples Of System.ServiceModel.Description.ContractDescription::GetContract