【问题标题】:local web service access from remote computer (localhost vs. ip address)从远程计算机访问本地 Web 服务(本地主机与 IP 地址)
【发布时间】:2017-04-20 21:53:38
【问题描述】:

我是使用网络服务的新手。

我使用 Visual Studio 2017 在 C# 中创建了一个 Web 服务(该服务是一个 .svc 文件)。

此 Web 服务已发布到远程计算机上的文件夹中。

当我连接到远程机器时,我可以使用 url 运行 web 服务:

http://localhost:1869/ServiceName.svc/

但是当我尝试从我的计算机运行 Web 服务时,我尝试通过将 'localhost' 替换为 ip 地址来修改 url,但它不起作用。

是否可以远程访问本地网络服务?

如果没有,发布 Web 服务以便远程访问它的最佳方式是什么?

感谢您的帮助!

-编辑-

请参阅下面的 Web.config 代码。

我尝试在远程机器上创建一个 Web 服务器并将 Visual Studio 解决方案项目 / 编译到 C:\inetpub\wwwroot 中,没有帮助

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="RsConnString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|RestDB.mdf;User Instance=true" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <services>
            <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
                <!-- Service Endpoints -->
                <!-- Unless fully qualified, address is relative to base address supplied above -->
                <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
                    <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
                </endpoint>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehaviour">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true" />
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="web">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data></configuration>

【问题讨论】:

  • 这取决于您托管服务的方式。它是自托管的,还是在 iis 上的?
  • 感谢您的回答!它是自托管的。
  • 您使用的是什么绑定 basicHttpBinding 、 wsHttpBinding 等?如果你能展示一些代码——你已经尝试过的等等,那就太好了。
  • 感谢 Digvijay 的帮助!我发布了 Web.config 代码
  • 你没有提供任何地址来监听(address="" 在你的配置中)并且没有提供任何基地址

标签: c# web-services wcf


【解决方案1】:

感谢您的帮助!

我能够按照那里的指示使其工作:link

归结为正确配置 IIS 和网站。

要回答的关键问题是:

您是否在 IIS 中启用了服务器级别的基本身份验证?

您是否启用了与 Web 管理服务的远程连接?

您是否启动了 Web 管理服务?

是否有管理服务委托规则?

您的防火墙是否允许通过 TCP 端口 8172 与服务器建立传入连接?

【讨论】:

    猜你喜欢
    • 2018-01-29
    • 1970-01-01
    • 2011-10-19
    • 2012-01-17
    • 2012-10-28
    • 2012-06-09
    • 2019-04-08
    • 1970-01-01
    • 2017-11-30
    相关资源
    最近更新 更多