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

  • SEARCH
  • Home
  • 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 115295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:59:47+00:00 2026-05-11T02:59:47+00:00

In the following config file excerpt, the WCF service has two endpoints. <service behaviorConfiguration=AtomTcpHub.Behavior

  • 0

In the following config file excerpt, the WCF service has two endpoints.

  <service behaviorConfiguration='AtomTcpHub.Behavior'             name='AtomTcpHub.HubTcp'>     <endpoint address='' binding='netTcpBinding'                name='AtomHubEndpoint' contract='AtomLib.IAtomPublisher'>       <identity>         <dns value='localhost' />       </identity>     </endpoint>     <endpoint address='mex' binding='mexHttpBinding'                name='' contract='IMetadataExchange' />     <host>       <baseAddresses>         <add baseAddress='http://localhost:8731/AtomTcpHub/' />         <add baseAddress='net.tcp://dv-pw/AtomTcpHub/' />       </baseAddresses>     </host>   </service> 

In my code there is discovery logic, which responds to a UDP request by replying with the connection Uri for the WCF service. Obtaining a collection of endpoints is straightforward.

System.Configuration.Configuration config = System.Configuration   .ConfigurationManager   .OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); ServicesSection section = config.SectionGroups['system.serviceModel']   .Sections['services'] as ServicesSection; ServiceEndpointElementCollection seec =    section.Services['AtomTcpHub.HubTcp'].Endpoints; 

The problem is extracting the ServiceEndpointElement. We can have it by index:

ServiceEndpointElement see = seec[0]; 

but this is brittle; if the order of nodes changes it will break. Visual Studio tells me there is another indexer permitting an object value, but there is no further indication. Experimentation tells me that it isn’t the value of the name attribute.

The following code works, but it’s just hideous.

string serviceEndpointUri; foreach(ServiceEndpointElement serviceEndpointElement in seec)   if (serviceEndpointElement.Name == 'AtomHubEndpoint')   {     _serviceEndpointUri = serviceEndpointElement.Address.AbsoluteUri;     break;   } 

Is there a more direct or more elegant way to do this?

  • 1 1 Answer
  • 2 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. 2026-05-11T02:59:48+00:00Added an answer on May 11, 2026 at 2:59 am

    You could always use some Linq to accomplish this, to simply shorten things a bit.

    ServiceEndpointElement element = seec.OfType<ServiceEndpointElement>() .FirstOrDefault(s => s.Name == 'AtomHubEndpoint'); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following text in xml file: <Config Builder=LP Wizard> <Libraries> <Library Name=XCAMSource/>
I'm using the following web.config to enable tracing for my WCF service. While the
I have the following config file: <system.diagnostics> <trace autoflush=true indentsize=1 > <listeners> <add name=dbgTrace
I have the following config file for solr: <requestHandler name=/update/extract startup=lazy class=solr.extraction.ExtractingRequestHandler > <lst
Is it possible to transform the following Web.config appSettings file: <appSettings> <add key="developmentModeUserId" value="00297022"
Looking for a way to read the following config file sample using a multi
In my ASP.NET's Web Config file I have the following location elements defined: <location
I have the following web config file. I am having some difficulty in retrieving
I have a Windows program with the following flow: generated config file -> user
I have a C# application and the following is an excerpt from my Web.config

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.