找不到 WCF 服务资源

WCF service resource cannot be found

我有一个在本地主机上运行良好的 REST WCF 服务,但是 returns 在线部署时出现以下错误:

The resource cannot be found.

注意:我的 WCF 服务位于以下路径下:

https://example.com/api/v1/Service.svc

我很确定问题是路径错误,我尝试了太多解决方案,但 none 有效。

下面是我的Web.config:

<system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Service">
        <endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="JsonBehavior" listenUri="/">
          <identity>
            <dns value="" />
          </identity>
        </endpoint>  
      </service>
    </services>

    <bindings>
      <webHttpBinding>
        <binding crossDomainScriptAccessEnabled="true" maxBufferSize="2000000000" maxReceivedMessageSize="2000000000" transferMode="Buffered">
          <readerQuotas maxDepth="250000000" maxStringContentLength="250000000" maxArrayLength="250000000" maxBytesPerRead="250000000" maxNameTableCharCount="250000000" />
          <security mode="None" />
        </binding>
      </webHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="JsonBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true">          
    </serviceHostingEnvironment>
  </system.serviceModel>

我尝试过的解决方案:


方案一:

将基地址添加到 system.serviceModel > Services > Service

<host>
    <baseAddresses>
        <add baseAddress="https://example.com/" />
    </baseAddresses>
</host>

方案二:

system.serviceModel > serviceHostingEnvironment

添加基地址前缀
<baseAddressPrefixFilters>
    <add prefix="https://example.com/" />
</baseAddressPrefixFilters>

方案三:

摆弄端点 addresslistenUri

<endpoint address="https://example.com/api/v1/Service.svc" binding="webHttpBinding" contract="IService" behaviorConfiguration="JsonBehavior" listenUri="/">

如何在 Web.config 中定义正确的路径?

注意:在另一个项目中,我的 .svc 文件位于根目录中,我使用了上面发布的相同 Web.config 并且一切正常。所以肯定是路径问题

最后,我通过更改 <security mode="Transport" /> 解决了问题,它成功了!