I copy addresses from the endpoints to an array that should only hold the endpoint addresses. This works but it seems so old school :/
Can I make this faster, better, more sexy (LINQ)?
public static EndpointAddress[] Find()
{
EndpointAddress[] endpointAddresses = null;
var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
var findResponse = discoveryClient.Find(
new FindCriteria(
typeof(ICommunicationService)));
if(findResponse != null)
{
if(findResponse.Endpoints.Count > 0)
{
endpointAddresses = new EndpointAddress[findResponse.Endpoints.Count];
for (int i = 0; i <= findResponse.Endpoints.Count; i++)
{
endpointAddresses[i] = findResponse.Endpoints[i].Address;
}
}
}
return endpointAddresses ?? new EndpointAddress[0];
}
i <= findResponse.Endpoints.Count
should cause an index out of range error. – CodesInChaos Jun 29 at 13:08var
forfindResponse
since it is impossible to figure what is the type just by looking at the code! – TopinFrassi Jun 29 at 19:49