DiscoveryUtility.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / DiscoveryUtility.cs / 1305376 / DiscoveryUtility.cs

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

namespace System.ServiceModel.Discovery 
{
    using System.Collections.ObjectModel; 
    using System.Runtime; 
    using System.ServiceModel.Description;
    using System.ServiceModel.Discovery.Version11; 
    using System.ServiceModel.Discovery.VersionApril2005;
    using System.ServiceModel.Discovery.VersionCD1;

    class DiscoveryUtility 
    {
        public static Collection ToEndpointDiscoveryMetadataCollection( 
            Collection endpointDiscoveryMetadataApril2005Collection) 
        {
            Collection endpointDiscoveryMetadataCollection = new Collection(); 
            foreach (EndpointDiscoveryMetadataApril2005 endpointDiscoveryMetadataApril2005 in endpointDiscoveryMetadataApril2005Collection)
            {
                endpointDiscoveryMetadataCollection.Add(endpointDiscoveryMetadataApril2005.ToEndpointDiscoveryMetadata());
            } 
            return endpointDiscoveryMetadataCollection;
        } 
 
        public static Collection ToEndpointDiscoveryMetadataCollection(
            Collection endpointDiscoveryMetadataCD1Collection) 
        {
            Collection endpointDiscoveryMetadataCollection = new Collection();
            foreach (EndpointDiscoveryMetadataCD1 endpointDiscoveryMetadataCD1 in endpointDiscoveryMetadataCD1Collection)
            { 
                endpointDiscoveryMetadataCollection.Add(endpointDiscoveryMetadataCD1.ToEndpointDiscoveryMetadata());
            } 
            return endpointDiscoveryMetadataCollection; 
        }
 
        public static Collection ToEndpointDiscoveryMetadataCollection(
            Collection endpointDiscoveryMetadata11Collection)
        {
            Collection endpointDiscoveryMetadataCollection = new Collection(); 
            foreach (EndpointDiscoveryMetadata11 endpointDiscoveryMetadata11 in endpointDiscoveryMetadata11Collection)
            { 
                endpointDiscoveryMetadataCollection.Add(endpointDiscoveryMetadata11.ToEndpointDiscoveryMetadata()); 
            }
            return endpointDiscoveryMetadataCollection; 
        }

        public static ContractDescription GetContract(Type contractType)
        { 
            Fx.Assert(contractType != null, "The discoveryContractType attribute must not be null.");
 
            ContractDescription discoveryContract = ContractDescription.GetContract(contractType); 
            OperationBehaviorAttribute operationBehaviorAttribute;
            foreach (OperationDescription operationDescription in discoveryContract.Operations) 
            {
                operationBehaviorAttribute = operationDescription.Behaviors.Find();
                if (operationBehaviorAttribute == null)
                { 
                    operationBehaviorAttribute = new OperationBehaviorAttribute();
                    operationDescription.Behaviors.Add(operationBehaviorAttribute); 
                } 

                operationBehaviorAttribute.PreferAsyncInvocation = true; 
            }

            return discoveryContract;
        } 

        public static DiscoveryMessageSequence ToDiscoveryMessageSequenceOrNull(DiscoveryMessageSequenceApril2005 messageSequence) 
        { 
            if (messageSequence == null)
            { 
                return null;
            }
            else
            { 
                return messageSequence.ToDiscoveryMessageSequence();
            } 
        } 

        public static DiscoveryMessageSequence ToDiscoveryMessageSequenceOrNull(DiscoveryMessageSequenceCD1 messageSequence) 
        {
            if (messageSequence == null)
            {
                return null; 
            }
            else 
            { 
                return messageSequence.ToDiscoveryMessageSequence();
            } 
        }

        public static DiscoveryMessageSequence ToDiscoveryMessageSequenceOrNull(DiscoveryMessageSequence11 messageSequence)
        { 
            if (messageSequence == null)
            { 
                return null; 
            }
            else 
            {
                return messageSequence.ToDiscoveryMessageSequence();
            }
        } 

        public static bool IsCompatible(OperationContext context, IContextChannel channel) 
        { 
            return ((context != null) &&
                (context.InternalServiceChannel != null) && 
                (object.ReferenceEquals(context.InternalServiceChannel.Proxy, channel)));
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

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