You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET构建REST服务访问提示资源不存在及元数据发布禁用问题

问题1说明

“Metadata publishing for this service is currently disabled”提示不会影响REST服务的正常调用,该提示仅说明WCF默认关闭了SOAP协议所需的元数据(WSDL)发布能力,如果你不需要对外提供SOAP调用入口,可忽略该提示。

问题2原因

404报错是因为Web.config中WCF端点配置错误:你为endpoint配置了address="TestService",相当于在svc地址后额外加了一层路径前缀,你预期的/TestService.svc/Test实际对应配置的/TestService.svc/TestService/Test,所以访问前者找不到资源。


修复步骤

1. 解决404资源找不到问题

两种方案二选一即可:

  • 方案一:修改端点配置,移除多余的路径前缀
    找到Web.config中system.serviceModel/services/service/endpoint节点,将address属性改为空字符串:
    <endpoint address="" behaviorConfiguration="Test.REST.TestServiceAspNetAjaxBehavior"
      binding="webHttpBinding" contract="Test.REST.TestService" />
    
    修改后重启服务,访问https://localhost:44397/TestService.svc/Test即可正常返回"Hello"。
  • 方案二:不修改配置,直接访问符合当前配置的地址:https://localhost:44397/TestService.svc/TestService/Test,也可正常获取返回结果。

2. (可选)关闭元数据发布提示

如果需要访问TestService.svc时展示正常的服务说明页,可按以下步骤修改配置开启元数据发布:

  1. 在system.serviceModel/behaviors节点下新增服务行为配置:
    <serviceBehaviors>
      <behavior name="TestServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    
  2. 给service节点添加behaviorConfiguration属性引用上述行为:
    <service name="Test.REST.TestService" behaviorConfiguration="TestServiceBehavior">
    

修改后重启服务即可生效。


内容的提问来源于stack exchange,提问作者HowDoICSharply

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 13:30:02