【问题标题】:WCF service metadata (wsdl) cannot be accessed: error 400无法访问 WCF 服务元数据 (wsdl):错误 400
【发布时间】:2021-04-17 05:41:50
【问题描述】:

我在新安装时遇到了 WCF 元数据问题(Windows Server 2016 上的 IIS 10)

情况

  • WCF 服务运行良好(就像以前的安装一样)

  • wsdl 的导航(通过浏览器)不再可能,或者更好

  • http://ServiceA/ServiceA.svc: 是(网页可用)但指向 xml 的链接不起作用(来自 IIS 的错误 400)

  • https://ServiceA/ServiceA.svc:连页面都没有

    此外,在 serviceMetadata 中声明使用 https 而非 http,这与刚刚描述的行为相反。

下面是 web.config 的摘录

<services>
      <service behaviorConfiguration="ServiceBehavior" name="...">
        <endpoint address="https://<fqdn>/ServiceA/ServiceA.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="wsHttpEndpointBinding"
                  name="WsHttpBinding"
                  contract="ServiceContracts.IServiceA">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
    ...

可能与名称解析有关吗? PC 名称为 AAAAAA,FQDN 为 BBBBB.domain.ext

感谢您的任何建议 L.

【问题讨论】:

  • 您好,问题解决了吗?如果您认为我的回复对您有帮助,您可以将其标记为答案。
  • 嗨。抱歉,我有段时间没上网。明天我将按照您的建议尝试删除端点地址。我很困惑,因为在开始时我设置了相对路径(/ServiceA/ServiceA.svc)并且 svc 是可访问的,但它不是服务本身。设置完整的url,情况已经交换(没有svc,但服务ok)。我会告诉你。同时,谢谢。

标签: wcf metadata http-status-code-400 svc


【解决方案1】:

IIS中部署的WCF服务无需在web.config中设置端点地址。

这是我的演示:

<?xml version="1.0"?>
<configuration>

  <appSettings/>
  <connectionStrings/>
  <system.web>
    <compilation debug="true">
    </compilation>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
    <authentication mode="Windows" />
    <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
      -->
  </system.web>
  <system.webServer>
    <!--
        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.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
  <system.serviceModel>
    <services>
      <service name="WcfService25.Service1" behaviorConfiguration="WcfService25.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="basicHttpBinding" contract="WcfService25.IService1">
          <!-- 
              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.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService25.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false 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>
    </behaviors>
  </system.serviceModel>

</configuration>

这是 web.config。本项目为模板项目。

IIS中WCF服务的基地址如下:

【讨论】:

  • 嗨丁。谢谢你的回复,我按照你的建议做了。到目前为止,VM 处于测试阶段(可通过内部网络访问)并且运行良好:svc 导航和服务均可运行。我的疑问是我们什么时候开始生产,因为目前我可以看到 ServiceA.svc 使用“https://[MACHINE_NAME]/ServiceA/ServiceA.svc”(按照您的建议设置地址 =“”)解决,因此,在开放互联网我认为这将取决于我的 Ops 同事如何配置 DNS
  • 我们也可以通过IP地址访问。
  • 嗨。当我进入测试版生产时,我会知道的。不是马上。别担心,如果你的答案肯定是那个,我很乐意标记它。谢谢
猜你喜欢
  • 1970-01-01
  • 2015-09-09
  • 1970-01-01
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 2011-08-28
  • 2011-10-28
  • 1970-01-01
相关资源
最近更新 更多