如何远程访问IIS .NET V4.5托管的Web服务

时间:2017-04-22 17:32:48

标签: c# asp.net web-services wcf iis

我使用Visual Studio 2017创建了一个Web服务,该服务使用带有.NET V4.5的IIS托管在远程计算机(远程服务器)上。

使用IIS管理器发布到IIS的Web服务。

我无法更改" IP地址"除了"所有未分配的"。如果我在下拉菜单中选择可用的IP地址,则该网站无法正常工作(返回错误:" HTTP错误404.找不到请求的资源。")。

如果我使用"所有未分配"使用"主机名" " localhost",它在本地运作良好。

这意味着我可以在网络浏览器中输入网址(http://localhost:81/RestServiceImpl.svc)并按预期执行网络服务。

我的问题是:如何在这台远程计算机上托管我的Web服务,以便我可以使用url从任何计算机访问它,其中localhost将被远程计算机IP地址替换?

请参阅下面我的web.config文件(可能是因为我没有使用正确的绑定,或者隐藏了远程机器的IP地址):

<?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>
    <handlers>
      <remove name="svc-Integrated" />
      <add name=".svc" verb="*" path="*.svc" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, &#xD;&#xA;System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                                                                                                   />
    </handlers>

    <!--
    <modules runAllManagedModulesForAllRequests="true"/>
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <modules>
      <remove name="ServiceModel" />
    </modules>
    <directoryBrowse enabled="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>

0 个答案:

没有答案