Example #1
0
        /// <summary>
        /// Extracts the listening URI from a binding context.
        /// </summary>
        /// <param name="context">The <see cref="BindingContext" />.</param>
        /// <returns>The <see cref="Uri" />.</returns>
        /// <exception cref="ArgumentNullException">Thrown if BindingContext.ListenUriBaseAddress is not specified.</exception>
        /// <exception cref="ArgumentException">Thrown if the URI does not have a valid LillTek URI scheme.</exception>
        protected Uri GetListenUri(BindingContext context)
        {
            Uri    uri;
            Uri    baseAddress;
            string relativeAddress;

            baseAddress     = context.ListenUriBaseAddress;
            relativeAddress = context.ListenUriRelativeAddress;

            if (baseAddress == null)
            {
                if (context.ListenUriMode == ListenUriMode.Unique)
                {
                    baseAddress = ServiceModelHelper.CreateUniqueUri();
                }
                else
                {
                    throw new ArgumentNullException("BindingContext.ListenUriBaseAddress");
                }
            }

            if (string.IsNullOrWhiteSpace(relativeAddress))
            {
                uri = baseAddress;
            }
            else
            {
                UriBuilder ub = new UriBuilder(baseAddress);

                if (!ub.Path.EndsWith("/"))
                {
                    ub.Path += "/";
                }

                uri = new Uri(ub.Uri, relativeAddress);
            }

            // Verify that the URI scheme is a valid LillTek scheme.

            switch (uri.Scheme.ToLowerInvariant())
            {
            case "lilltek.logical":
            case "lilltek.abstract":

                return(uri);        // OK

            default:

                throw new ArgumentException(string.Format("Invalid LillTek Messaging WCF Transport scheme [{0}].", uri.Scheme), "BindingContext.ListenUriBaseAddress");
            }
        }