【问题标题】:WCF cannot configure WSDL publishingWCF 无法配置 WSDL 发布
【发布时间】:2023-03-05 10:56:01
【问题描述】:

我想为我创建的 Web 服务启用 WSDL 检索。我可以通过我制作的 .svc 文件“调用”网络服务:

http://localhost/test.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Project.MyService" CodeBehind="MyService.svc.cs" %>

调用该页面会给出标准的 .NET 消息,指出“此服务的元数据发布当前已禁用”。带有启用发布的说明。

我按照说明添加了 web.config 条目,但是调用 http://localhost/test.svc?wsdl 会产生相同的结果...如何为我的 web 服务启用 WSDL 发布?

web.config 条目

  <service name="Project.IMyService" behaviorConfiguration="MyServiceTypeBehaviors" >
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" 
              address="mex"
              />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/test.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceTypeBehaviors">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

【问题讨论】:

    标签: wcf configuration wsdl


    【解决方案1】:

    mex 端点和 httpGetEnabled 看起来没问题。此链接更详细地介绍了该主题,并且可能有用。

    http://msdn.microsoft.com/en-us/library/ms788760.aspx

    【讨论】:

      【解决方案2】:

      听起来很疯狂,但只需从服务定义中删除 behaviorConfiguration="MyServiceTypeBehaviors" 并让行为匿名(没有名称)。它会保留

      <services>
           <service name="WcfServiceLibrary1.IMyService" >
          <endpoint contract="IMetadataExchange" binding="mexHttpBinding" 
                    address="mex"
                    />
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost/test.svc"/>
            </baseAddresses>
          </host>
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior >
            <serviceMetadata httpGetEnabled="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
      

      【讨论】:

      • 我最终使用了 Visual Studio 提供的 WCF 配置工具。这会产生与此类似的结果。谢谢!
      • 谢谢,这只花了我 2 个小时。命名这些行为对我来说已经没有意义了。
      猜你喜欢
      • 2021-03-17
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 2019-07-28
      • 2010-12-11
      • 2016-01-07
      • 2011-12-12
      • 2023-04-04
      相关资源
      最近更新 更多