c# - Indexing ServiceEndpointElementCollection -


In the following config file version, the WCF service has two end points.

& lt; Service Behavior Configuration = "Atom TCPHubWeaver" name = "AtomTechHub.httpp" & gt; & Lt; Endpoint address = "" binding = "net TCP binding" name = "Atom hub edapoint" contract = "atlib. ITM publisher" & gt; & Lt; Identity & gt; & Lt; Dns value = "localhost" /> & Lt; / Identification & gt; & Lt; / Endpoint & gt; & Lt; Endpoint address = "mex" binding = "mx htebbiding" name = "" contract = "iamadadataexchange" /> & Lt; Host & gt; & Lt; BaseAddresses & gt; & Lt; BaseAddress = "http: // localhost: 8731 / AtomTcpHub /" /> Add & lt; BaseAddress = "net.tcp: // dv-pw / AtomTcpHub /" / & gt; Add & lt; / BaseAddresses & gt; & Lt; / Host & gt; & Lt; / Services & gt;

My code has Discovery Logic, which responds to the UCR request, with the connection URI for the WCF service. Getting a collection of end points is straightforward.

  System Configuration. Configuration Config = System Configuration. Configuration Manager Open Excel Configuration (System Configuration. Configure User Level NONE); ServicesSection section = config.SectionGroups ["system.serviceModel"]. Access ["Services"] as ServicesSection; ServiceEndpointElementCollection seec = section.Services ["AtomTcpHub.HubTcp"]. Endpoint; Removing the problem  ServiceEndpointElement  We can get it by index: 

  View the servixpoint element = see [0] ];  

But it is brittle; If the sequence of nodes changes, then it will break. Visual Studio tells me that another indicator is an object value, but there is no other sign. The experiment tells me that the value of the name attribute is not

the following code works , but it is just fatal .

  String Service EndpointUri; 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?

You can always use some Linux to complete it, just a few things short can do.

Sewpointpoint element element = see.offtype & lt; Seduced PoE Element & gt; (). FirstOther Default (S => S.Name == "Atom HubPoint");

Comments