When I access the WCF service locally it works. To do this I type into my browser: http://localhost:54123/MyService/GetValue
This shows my expected json formatted output. However, when accessing remotely using http://myIPAddress:54123/MyService/GetValue I get ERR_CONNECTION_TIMED_OUT in Chrome.
I have my inbound IP whitelisted for all TCP ports, so I am not sure why I would be unable to access remotely. This is being hosted on an amazon EC2 instance if that makes any difference.
Here is the code I have in my main() method for hosting the service via Topshelf
const string serviceUri = "http://localhost:54123/MyService";
var host = HostFactory.New(configurator =>
{
configurator.Service<WcfServiceWrapper<MyServiceClass, IMyServiceClass>>(serviceConfigurator =>
{
serviceConfigurator.ConstructUsing(x =>
new WcfServiceWrapper<MyServiceClass, IMyServiceClass>("MyService", serviceUri));
serviceConfigurator.WhenStarted(service => service.Start());
serviceConfigurator.WhenStopped(service => service.Stop());
});
configurator.RunAsLocalSystem();
configurator.SetDescription("Runs My Service.");
configurator.SetDisplayName("MyService");
configurator.SetServiceName("MyService");
});
Here is the relevant code from my WcfWrapper start() method
var webHttpBinding = new WebHttpBinding(WebHttpSecurityMode.None);
_serviceHost.AddServiceEndpoint(typeof(TServiceContract), webHttpBinding, _serviceUri);
var webHttpBehavior = new WebHttpBehavior
{
DefaultOutgoingResponseFormat = WebMessageFormat.Json
};
_serviceHost.Description.Endpoints[0].Behaviors.Add(webHttpBehavior);
_serviceHost.Open();
openSucceeded = true;
Below is what I have in my config file
<configuration>
<system.serviceModel>
<services>
<service name="MyServiceClassNS.MyServiceClass">
<host>
<baseAddresses>
<add baseAddress="http://myIPAddress:54123/MyService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Most likely cause of the problem is that the firewall is blocking the call.