WsdlContractConversionContext.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Description / WsdlContractConversionContext.cs / 2 / WsdlContractConversionContext.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.ServiceModel.Description 
{
 
    using System.Xml; 

    using System.ServiceModel.Channels; 

    using System.Xml.Schema;
    using System.Collections.Generic;
    using System.Collections.ObjectModel; 
    using WsdlNS = System.Web.Services.Description;
 
    // This class is created as part of the export process and passed to 
    // Wsdlmporter and WsdlExporter implementations as a utility for
    // Correlating between the WSDL OM and the Indigo OM 
    // in the conversion process.
    public class    WsdlContractConversionContext
    {
 
        readonly ContractDescription contract;
        readonly WsdlNS.PortType wsdlPortType; 
 
        readonly Dictionary wsdlOperations;
        readonly Dictionary operationDescriptions; 
        readonly Dictionary wsdlOperationMessages;
        readonly Dictionary wsdlOperationFaults;
        readonly Dictionary messageDescriptions;
        readonly Dictionary faultDescriptions; 
        readonly Dictionary> operationBindings;
 
        internal WsdlContractConversionContext(ContractDescription contract, WsdlNS.PortType wsdlPortType) 
        {
 
            this.contract = contract;
            this.wsdlPortType = wsdlPortType;

            this.wsdlOperations = new Dictionary(); 
            this.operationDescriptions = new Dictionary();
            this.wsdlOperationMessages = new Dictionary(); 
            this.messageDescriptions = new Dictionary(); 
            this.wsdlOperationFaults = new Dictionary();
            this.faultDescriptions = new Dictionary(); 
            this.operationBindings = new Dictionary>();
        }

        internal IEnumerable ExportExtensions 
        {
            get 
            { 
                foreach (IWsdlExportExtension extension in contract.Behaviors.FindAll())
                { 
                    yield return extension;
                }

                foreach (OperationDescription operation in contract.Operations) 
                {
                    if (!WsdlExporter.OperationIsExportable(operation)) 
                    { 
                        continue;
                    } 

                    // In 3.0SP1, the DCSOB and XSOB were moved from before to after the custom behaviors.  For
                    // IWsdlExportExtension compat, run them in the pre-SP1 order.
                    // TEF QFE 367607 
                    Collection extensions = operation.Behaviors.FindAll();
                    for (int i = 0; i < extensions.Count;) 
                    { 
                        if (WsdlExporter.IsBuiltInOperationBehavior(extensions[i]))
                        { 
                            yield return extensions[i];
                            extensions.RemoveAt(i);
                        }
                        else 
                        {
                            i++; 
                        } 
                    }
                    foreach (IWsdlExportExtension extension in extensions) 
                    {
                        yield return extension;
                    }
                } 
            }
        } 
 

        public ContractDescription Contract { get { return contract; } } 
        public WsdlNS.PortType WsdlPortType { get { return wsdlPortType; } }

        public WsdlNS.Operation GetOperation(OperationDescription operation)
        { 
            return this.wsdlOperations[operation];
        } 
 
        public WsdlNS.OperationMessage GetOperationMessage(MessageDescription message)
        { 
            return this.wsdlOperationMessages[message];
        }

        public WsdlNS.OperationFault GetOperationFault(FaultDescription fault) 
        {
            return this.wsdlOperationFaults[fault]; 
        } 

        public OperationDescription GetOperationDescription(WsdlNS.Operation operation) 
        {
            return this.operationDescriptions[operation];
        }
 
        public MessageDescription GetMessageDescription(WsdlNS.OperationMessage operationMessage)
        { 
            return this.messageDescriptions[operationMessage]; 
        }
 
        public FaultDescription GetFaultDescription(WsdlNS.OperationFault operationFault)
        {
            return this.faultDescriptions[operationFault];
        } 

        // ------------------------------------------------------------------------------------------------- 
 
        internal void AddOperation(OperationDescription operationDescription, WsdlNS.Operation wsdlOperation)
        { 
            this.wsdlOperations.Add(operationDescription, wsdlOperation);
            this.operationDescriptions.Add(wsdlOperation, operationDescription);
        }
 
        internal void AddMessage(MessageDescription messageDescription, WsdlNS.OperationMessage wsdlOperationMessage)
        { 
            this.wsdlOperationMessages.Add(messageDescription, wsdlOperationMessage); 
            this.messageDescriptions.Add(wsdlOperationMessage, messageDescription);
        } 

        internal void AddFault(FaultDescription faultDescription, WsdlNS.OperationFault wsdlOperationFault)
        {
            this.wsdlOperationFaults.Add(faultDescription, wsdlOperationFault); 
            this.faultDescriptions.Add(wsdlOperationFault, faultDescription);
        } 
 
        internal Collection GetOperationBindings(WsdlNS.Operation operation)
        { 
            Collection bindings;
            if (!this.operationBindings.TryGetValue(operation, out bindings))
            {
                bindings = new Collection(); 
                WsdlNS.ServiceDescriptionCollection wsdlDocuments = WsdlPortType.ServiceDescription.ServiceDescriptions;
                foreach (WsdlNS.ServiceDescription wsdl in wsdlDocuments) 
                { 
                    foreach (WsdlNS.Binding wsdlBinding in wsdl.Bindings)
                    { 
                        if (wsdlBinding.Type.Name == WsdlPortType.Name && wsdlBinding.Type.Namespace == WsdlPortType.ServiceDescription.TargetNamespace)
                        {
                            foreach (WsdlNS.OperationBinding operationBinding in wsdlBinding.Operations)
                            { 
                                if (operationBinding.Name == operation.Name && WsdlImporter.Binding2DescriptionHelper.IsOperationBoundBy(operationBinding, operation))
                                { 
                                    bindings.Add(operationBinding); 
                                    break;
                                } 
                            }
                        }
                    }
                } 
                this.operationBindings.Add(operation, bindings);
            } 
            return bindings; 
        }
 
    }

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK