Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:27:56+00:00 2026-05-15T16:27:56+00:00

I have handhelds that need to communicate via basicHTTPBinding. I have a contract and

  • 0

I have handhelds that need to communicate via basicHTTPBinding. I have a contract and everything works as advertised.

I need to expand it to easily support changing to a test environment, training and of course production. I took the port route, thinking I could expose different endpoints with port differences, and based on the port, decide which database I wanted info from.

I cant seem to make this work, and so far have found no information anywhere that indicates it can be done. Since port is optional, it may not be.

Anyone done anything like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:27:57+00:00Added an answer on May 15, 2026 at 4:27 pm

    Although you can’t do what you want with the port you can accomplish this with a different path. Such as appending “/prod” or “/test” to your base address. I’ve included an example that illustrates this.

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    
    namespace WCFTest
    {
        class Program
        {
            static void Main()
            {
                List<Uri> baseAddresses = new List<Uri> { new Uri("http://localhost:1000/Prod"), new Uri("http://localhost:1000/Test") };
                ServiceHost wcfHost = new ServiceHost(typeof(SimpleWCF), new Uri[] {new Uri("http://localhost:1000")});
    
                foreach (ServiceEndpoint endpoint in SimpleWCF.CreateEndpoints(baseAddresses.ToArray()))
                {
                    wcfHost.AddServiceEndpoint(endpoint);
                }
    
                ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
                metadataBehavior.HttpGetEnabled = true;
                wcfHost.Description.Behaviors.Add(metadataBehavior);
    
                wcfHost.Open();
                Console.ReadLine();
                wcfHost.Close();
            }
        }
    
        [ServiceContract]
        public interface ISimpleWCF
        {
            [OperationContract]
            string TestMethod();
        }
    
        public class SimpleWCF : ISimpleWCF
        {
            /// <summary>
            /// Thread Synchronization Object.
            /// </summary>
            private static readonly object _syncRoot = new object();
    
            /// <summary>
            /// Static Instance of Class.
            /// </summary>
            private static volatile SimpleWCF _current;
    
            /// <summary>
            /// Initializes a new instance of the <see cref="WebDataExchange"/> class.
            /// </summary>
            public SimpleWCF()
            {
                this.Contract = ContractDescription.GetContract(typeof(ISimpleWCF), GetType());
            }
    
            /// <summary>
            /// Gets or sets the contract.
            /// </summary>
            /// <value>The contract.</value>
            private ContractDescription Contract { get; set; }
    
            /// <summary>
            /// Gets the current instance of the SimpleWCF Object.
            /// </summary>
            /// <value>The current SimpleWCF Object.</value>
            public static SimpleWCF Current
            {
                get
                {
                    if (_current != null)
                    {
                        return _current;
                    }
    
                    lock (_syncRoot)
                    {
                        if (_current == null)
                            _current = new SimpleWCF();
    
                    }
    
                    return _current;
                }
            }
    
            /// <summary>
            /// Creates an Enpoint Collection.
            /// </summary>
            /// <param name="addresses">The addresses.</param>
            /// <returns>A Collection of ServiceEndpoints.</returns>
            public static Collection<ServiceEndpoint> CreateEndpoints(Uri[] addresses)
            {
                Collection<ServiceEndpoint> endpointCollection = new Collection<ServiceEndpoint>();
    
                foreach (Uri uriAddress in addresses)
                {
                    EndpointAddress address = new EndpointAddress(uriAddress);
    
                    BasicHttpSecurityMode securityMode = address.Uri.Scheme == Uri.UriSchemeHttps ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None;
                    BasicHttpBinding endpointBinding = new BasicHttpBinding(securityMode);
    
                    ServiceEndpoint endpoint = new ServiceEndpoint(Current.Contract, endpointBinding, address);
                    endpoint.ListenUriMode = ListenUriMode.Explicit;
                    endpointCollection.Add(endpoint);
                }
    
                return endpointCollection;
            }
    
            #region ISimpleWCF Members
    
            string ISimpleWCF.TestMethod()
            {
                if (OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.EndsWith("Prod"))
                    return "Hello Prod!";
                else return "Hello Test!";
            }
    
            #endregion
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm writing an ASP.Net MVC intranet application which is accessed via handhelds and
I have a .NET Windows Mobile 5.0 application that is used for data collection.
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
i have a input tag which is non editable, but some times i need
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.