Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF F# - Handling Service Shutdown Gracefully on Client
    text
    copied!<p>I have some experimental code basically just trying to make a simple scenario work. I have one client that is streaming data to multiple services. The problem I have is that if one of the services does not shutdown gracefully I get an EndpointNotFoundException which I can't seem to handle. Below is my attempt at handling this which is failing. In reality I would like to remove the failed service channel from the list of channels and continue on streaming data to the services which are still up and running. The timer stuff simply gives the services a chance to start up before the data streaming starts.</p> <pre><code>let prices = returns a seq of data that is streamed. type ReplayDataStream(prices) = let evt = new Event&lt;_&gt;() member x.Replay() = async { for line, delay in prices do do! Async.Sleep(delay) evt.Trigger(line) } |&gt; Async.StartImmediate member x.PriceChanged = evt.Publish let main() = let addresses = new ResizeArray&lt;EndpointAddress&gt;() let announcementService = new AnnouncementService() let createChannels addresses = let channels = new ResizeArray&lt;IInputDataService&gt;() for (address:EndpointAddress) in addresses do let channelFactory = new ChannelFactory&lt;IInputDataService&gt;(new BasicHttpBinding(), address) let channel = channelFactory.CreateChannel() (channel :?&gt; ICommunicationObject).Faulted.Add(fun x -&gt; (channel :?&gt; ICommunicationObject).Abort() channels.Remove(channel) |&gt; ignore ) channels.Add(channel) channels let sendMessage(args:ElapsedEventArgs) = let channels = createChannels addresses for financialDataStream in prices do let replayDataStreamA = new ReplayDataStream(financialDataStream) for channel in channels do try //This is where it blows up and the try block isn't catching the exception. replayDataStreamA.PriceChanged.Add(channel.InputStringData) with | :? EndpointNotFoundException as ex -&gt; Console.WriteLine(ex.ToString()) | :? CommunicationException as ex -&gt; Console.WriteLine(ex.ToString()) | :? Exception as ex -&gt; Console.WriteLine(ex.ToString()) replayDataStreamA.Replay() let timer = new System.Timers.Timer() timer.Enabled &lt;- true timer.AutoReset &lt;- false timer.Interval &lt;- 30000.0 timer.Start() timer.Elapsed.Add(sendMessage) announcementService.OnlineAnnouncementReceived.Add(fun e -&gt; Console.WriteLine(e.EndpointDiscoveryMetadata.Address) addresses.Add(e.EndpointDiscoveryMetadata.Address) ) announcementService.OfflineAnnouncementReceived.Add(fun e -&gt; Console.WriteLine(e.EndpointDiscoveryMetadata.Address) addresses.Remove(e.EndpointDiscoveryMetadata.Address) |&gt; ignore ) let announcementServiceHost = new ServiceHost(announcementService) try announcementServiceHost.AddServiceEndpoint(new UdpAnnouncementEndpoint()); announcementServiceHost.Open(); with | :? System.ServiceModel.CommunicationException as ex -&gt; Console.WriteLine(ex.ToString()) | :? System.TimeoutException as ex -&gt; Console.WriteLine(ex.ToString()) printfn "%s" "Hit any key to close." Console.ReadKey() |&gt; ignore </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload