简体   繁体   English

远程访问WCF服务时发生超时错误

[英]Timeout error when accessing WCF service remotely

When I access the WCF service locally it works. 当我在本地访问WCF服务时,它可以工作。 To do this I type into my browser: http://localhost:54123/MyService/GetValue 为此,我在浏览器中输入: http:// localhost:54123 / MyService / GetValue

This shows my expected json formatted output. 这显示了我期望的json格式的输出。 However, when accessing remotely using http://myIPAddress:54123/MyService/GetValue I get ERR_CONNECTION_TIMED_OUT in Chrome. 但是,当使用http:// myIPAddress:54123 / MyService / GetValue进行远程访问时,我在Chrome中收到ERR_CONNECTION_TIMED_OUT。

I have my inbound IP whitelisted for all TCP ports, so I am not sure why I would be unable to access remotely. 我已将所有TCP端口的入站IP列入白名单,因此我不确定为什么无法远程访问。 This is being hosted on an amazon EC2 instance if that makes any difference. 如果有任何区别,它将托管在Amazon EC2实例上。

Here is the code I have in my main() method for hosting the service via Topshelf 这是我在main()方法中通过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 这是我的WcfWrapper start()方法中的相关代码

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>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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