Click here to Skip to main content
15,893,161 members
Articles / Programming Languages / C#

WS-Discovery for WCF

Rate me:
Please Sign up or sign in to vote.
4.95/5 (31 votes)
27 Nov 2008CPOL12 min read 139.8K   3.3K   86  
This article describes the design, implementation, and usage of WS-Discovery for Windows Communication Foundation (WCF).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.ServiceModel.Channels;
using Masieri.ServiceModel.WSDiscovery.Helpers.BindingMementos.Transport;
using Masieri.ServiceModel.WSDiscovery.Helpers.BindingMementos.MessageEncoding;
using Masieri.ServiceModel.WSDiscovery.Helpers;

//*****************************************************************************
//    Description.....WS-Discovey for WCF
//                                
//    Author..........Claudio Masieri, claudio@claudiomasieri.it
//    Copyright © 2008 ing.Masieri Claudio. (see included license.rtf file)    
//                        
//    Date Created:    06/06/06
//
//    Date        Modified By     Description
//-----------------------------------------------------------------------------
//    01/10/08    Claudio Masieri     First Release
//*****************************************************************************
namespace Masieri.ServiceModel.WSDiscovery.Messages
{
  /// <summary>
  /// EndpointReference class
  /// </summary>
    public class EndpointReference
    {
      /// <summary>
      /// Initializes a new instance of the <see cref="EndpointReference"/> class.
      /// </summary>
        public EndpointReference()
        {

        }
        /// <summary>
        /// Gets or sets the address.
        /// </summary>
        /// <value>The address.</value>
        public string Address { get; set; }
        /// <summary>
        /// Gets or sets the reference parameters.
        /// </summary>
        /// <value>The reference parameters.</value>
        public object ReferenceParameters { get; set; }
        /// <summary>
        /// Gets or sets the metadata.
        /// </summary>
        /// <value>The metadata.</value>
        public object Metadata { get; set; }
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("<EndpointReference targetns=\"{0}\">", Constants.Addressing.Namespace10);
            sb.AppendFormat("<Address>{0}</Address>", this.Address);
            if (ReferenceParameters != null)
                sb.AppendFormat("<ReferenceParameters>{0}</ReferenceParameters>", this.ReferenceParameters.ToString());
            if (Metadata != null)
                sb.AppendFormat("<Metadata>{0}</Metadata>", this.Metadata.ToString());

            sb.Append("</EndpointReference>");
            return sb.ToString();
        }
        /// <summary>
        /// Froms the reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static EndpointReference FromReader(XmlReader reader)
        {
            EndpointReference ep = new EndpointReference();
            do
            {

                if (reader.IsStartElement() && reader.LocalName == "Address")
                {
                    ep.Address = reader.ReadElementContentAsString();
                }
                if (reader.IsStartElement() && reader.LocalName == "ReferenceParameters")
                {
                    if (reader.Read() && reader.IsStartElement() && reader.LocalName == "Binding")
                    {
                        List<BindingElement> bindings = BindingMemento.RestoreMemento(reader);
                        CustomBinding binding = new CustomBinding(bindings.ToArray());
                        ep.ReferenceParameters = binding;
                    
                    }
                }
                if (reader.IsStartElement() && reader.LocalName == "Metadata")
                {
                    //TODO:ep.Metadata = reader.ReadElementContentAsString();
                }
                if (!reader.IsStartElement() && reader.LocalName == "EndpointReference")
                {
                    return ep;
                }
            } while (reader.Read());
            return null;
        }

       

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions