在 IIS 中发布 WCF - 无法获取 wsdl 定义

WCF publish in IIS - can not get wsdl definition

我正在使用 IIS 10 和 Visual studio 2019。OS: windows 10

我刚刚创建了基本的 wcf 网站(WCF 服务应用程序)。很简单,只是一个基本的例子。

我尝试在调试模式下 运行 这个项目,使用 IIS express,运行ning WcfTestClient。很好,wsdl 是从 link 消耗的:http://localhost:62549/Service1.svc?wsdl

但是,我需要将此服务发布到 IIS。所以,我已经完成了配置发布:

很好,我在 IIS 中看到新创建的应用程序。

但是现在,我无法获取 wsdl 定义。 Link: http:///localhost/WcfService4/Service1.svc?wsdl

我做错了什么?

接口:

using System.ServiceModel;

namespace WcfService4
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);
    }
}

Class:

namespace WcfService4
{
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
}

标记:

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

Web.config:

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

    <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.7.2" />
        <httpRuntime targetFramework="4.7.2"/>
    </system.web>



    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MetadataBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>

        <services>
            <service behaviorConfiguration="MetadataBehavior" name="WcfService4.Service1">
                <endpoint address=""
                          binding="basicHttpBinding"
                          contract="WcfService4.IService1" />
                <endpoint address="mex"
                          binding="mexHttpBinding"
                          contract="IMetadataExchange" />
            </service>
        </services>

        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <directoryBrowse enabled="true"/>
    </system.webServer>

</configuration>

这个错误的原因是http激活在windows功能中是关闭的,你可以在控制->程序和功能中打开,select“打开Windows features on or off”,然后在您的 .net Framework 版本高级服务中打开 HTTP 激活。