部署在 azure 应用服务上的 Asp.net Web 应用程序中的服务 (.svc) 端点出现 404 未找到错误

发布于 2025-01-12 04:08:11 字数 4285 浏览 5 评论 0原文

我有一个 ASP.net Web 应用程序,在其中调用“https://webapp.azurewebsites.net/Services/DataServices.svc/GetSalesOrders”等服务端点来检索数据并执行 CRUD 操作。 这个应用程序在我的本地主机上运行良好,但是当我将其部署在 azure Web 服务上时,所有“../DataServices.svc/..”调用都会给出 404 未找到错误。我不知道如何解决这个问题,有人可以帮忙吗? 这是我的 web.Config 文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="ConnectionString" value="connectionstring" />
    
    <add key="RecordsPerPage" value="20" />
    <add key="ServiceUrl" value="http://portal.azurewebsites.net/Services/DataServices.svc/" />
  </appSettings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
    <httpRuntime executionTimeout="36000" maxRequestLength="1023750" />
    <authentication mode="Forms">
      <forms defaultUrl="DashBoard.aspx" loginUrl="login.aspx" />
    </authentication>
  </system.web>
  <system.serviceModel>
<bindings>
    <webHttpBinding>
      <binding maxReceivedMessageSize="10485760">
      </binding>
    </webHttpBinding>
  </bindings>  

    <services>
      <service name="ProjectName.Services.DataServices">
        <endpoint address="" binding="webHttpBinding" contract="ProjectName.Services.IDataServices" behaviorConfiguration="restfulbehaviour" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulbehaviour">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
                <clear />
                <add name="Access-Control-Allow-Origin" value="*" />
                <add name="X-Powered-By" value="ASP.NET" />
      </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true" />
    <defaultDocument>
      <files>
                <clear />
                <add value="login.aspx" />
                <add value="index.php" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="iisstart.htm" />
                <add value="default.aspx" />
      </files>    
    </defaultDocument>
    <validation validateIntegratedModeConfiguration="false" />
        <directoryBrowse enabled="true" />
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="ASP" areas="" verbosity="Verbose" />
                        <add provider="ASPNET" areas="AppServices,Infrastructure,Module,Page" verbosity="Verbose" />
                        <add provider="WWW Server" areas="ANCM,Authentication,Cache,CGI,Compression,FastCGI,Filter,Module,RequestNotifications,RequestRouting,Rewrite,Security,StaticFile,WebSocket" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="500" />
                </add>
            </traceFailedRequests>
        </tracing>
   </system.webServer>
 <system.web.extensions>
        <scripting>  
             <webServices>                                                   
                 <jsonSerialization maxJsonLength="2147483644" />                 
             </webServices>
        </scripting>
    </system.web.extensions>
</configuration>

I have a ASP.net web application in which I'm calling service endpoints like "https://webapp.azurewebsites.net/Services/DataServices.svc/GetSalesOrders" to retrieve data and do CRUD operations.
This app works fine on my localhost but when I deployed it on azure web service, all the "../DataServices.svc/.." calls are giving 404 not found error. I'm not sure how to resolve this, can anyone please help?
This is my web.Config file

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="ConnectionString" value="connectionstring" />
    
    <add key="RecordsPerPage" value="20" />
    <add key="ServiceUrl" value="http://portal.azurewebsites.net/Services/DataServices.svc/" />
  </appSettings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
    <httpRuntime executionTimeout="36000" maxRequestLength="1023750" />
    <authentication mode="Forms">
      <forms defaultUrl="DashBoard.aspx" loginUrl="login.aspx" />
    </authentication>
  </system.web>
  <system.serviceModel>
<bindings>
    <webHttpBinding>
      <binding maxReceivedMessageSize="10485760">
      </binding>
    </webHttpBinding>
  </bindings>  

    <services>
      <service name="ProjectName.Services.DataServices">
        <endpoint address="" binding="webHttpBinding" contract="ProjectName.Services.IDataServices" behaviorConfiguration="restfulbehaviour" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulbehaviour">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
                <clear />
                <add name="Access-Control-Allow-Origin" value="*" />
                <add name="X-Powered-By" value="ASP.NET" />
      </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true" />
    <defaultDocument>
      <files>
                <clear />
                <add value="login.aspx" />
                <add value="index.php" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="iisstart.htm" />
                <add value="default.aspx" />
      </files>    
    </defaultDocument>
    <validation validateIntegratedModeConfiguration="false" />
        <directoryBrowse enabled="true" />
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="ASP" areas="" verbosity="Verbose" />
                        <add provider="ASPNET" areas="AppServices,Infrastructure,Module,Page" verbosity="Verbose" />
                        <add provider="WWW Server" areas="ANCM,Authentication,Cache,CGI,Compression,FastCGI,Filter,Module,RequestNotifications,RequestRouting,Rewrite,Security,StaticFile,WebSocket" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="500" />
                </add>
            </traceFailedRequests>
        </tracing>
   </system.webServer>
 <system.web.extensions>
        <scripting>  
             <webServices>                                                   
                 <jsonSerialization maxJsonLength="2147483644" />                 
             </webServices>
        </scripting>
    </system.web.extensions>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

著墨染雨君画夕 2025-01-19 04:08:11

发现问题后,发现是 SSL 造成的。我的应用程序是针对 http 构建的,并且 Azure AppService 的设置是针对 https 配置的,这就是我收到 404 的原因。

Found the issue, turns out it was due to SSL. My app was built for http and settings of Azure AppService was configured for https, that's why I was getting 404.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文