简体   繁体   中英

Timeout error when accessing WCF service remotely

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>

问题的最可能原因是防火墙阻止了该呼叫。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM