I'm implementing a service host with the Azure Service Bus Relay. The implementation is very straight forward:
Program.cs:
public class Program { public static void Main(string[] args) { var random = new Random(Environment.TickCount); ServiceHost sh = new ServiceHost(typeof(ProblemSolver)); var endpoint = sh.Description.Endpoints[0]; var serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); endpoint.Behaviors.Add(serviceRegistrySettings); string randomText = random.Next().ToString(); var listenUri = new Uri(endpoint.Address.Uri, randomText + "/"); endpoint.ListenUri = listenUri; sh.Open(); Console.WriteLine("Hosted: " + randomText); Console.ReadLine(); sh.Close(); } }
app.config:
<bindings><netTcpRelayBinding><binding name="default"><security mode="None" relayClientAuthenticationType="RelayAccessToken" /></binding></netTcpRelayBinding></bindings><services><service name="RelayPrototype.ProblemSolver"><endpoint contract="RelayServiceContract.IProblemSolver" binding="netTcpRelayBinding" bindingConfiguration="default" address="sb://test.servicebus.windows.net/problemSolver/" listenUri ="sb://test.servicebus.windows.net/problemSolver/" behaviorConfiguration="sbTokenProvider"/></service></services><behaviors><endpointBehaviors><behavior name="sbTokenProvider"><transportClientEndpointBehavior><tokenProvider><sharedAccessSignature keyName="RootManageSharedAccessKey" key="[mykey]" /></tokenProvider></transportClientEndpointBehavior></behavior></endpointBehaviors></behaviors>
The problem I'm facing is that once this is hosted, it is periodically disconnected after an interval of 2 minutes.
At this point, the TCP state of the service host changed from ESTABLISHEDto CLOSE_WAIT.
Monitoring the TCP traffics, I found that the source ns-sb2-prod-sg3-001.cloudapp.net sent a packet that contains FIN flag, which i suspect might have caused the disconnection.
The service host will try again to establish the connection to Azure after some time. Once the connection is established again, the disconnection cycle continues.
However, this scenario only happen on my local machine. The service is hosted fine on machines in other environment setup.
Could this be my implementation of the service host or is it something to do with the local network?