找不到WCF服务资源

时间:2018-06-21 14:38:27

标签: .net web-services wcf web-config wcf-endpoint

我有一个REST WCF服务,可以在localhost上正常工作,但是在联机部署时返回以下错误:

  

找不到资源。

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

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

我很确定问题出在路径错误,我尝试了太多解决方案,但都没有奏效。

下面是我的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>

我尝试过的解决方案:


解决方案1:

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

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

解决方案2:

system.serviceModel > serviceHostingEnvironment添加基地址前缀

<baseAddressPrefixFilters>
    <add prefix="https://example.com/" />
</baseAddressPrefixFilters>

解决方案3:

使用端点addresslistenUri

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

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

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

1 个答案:

答案 0 :(得分:0)

最后,我通过更改<security mode="Transport" />解决了该问题,并且有效!