首页 > 解决方案 > WCF 在 IIS 中发布 - 无法获取 wsdl 定义

问题描述

我正在使用 IIS 10 和 Visual Studio 2019。操作系统:Windows 10

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

我试图在调试模式下运行这个项目,使用 IIS express,运行 WcfTestClient。一切都好,wsdl 是从链接消费的:http://localhost:62549/Service1.svc?wsdl

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

在此处输入图像描述

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

但是现在,我无法得到 wsdl 的定义。链接:http://localhost/WcfService4/Service1.svc?wsdl

在此处输入图像描述

我在这里做错了什么?

界面:

using System.ServiceModel;

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

班级:

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" %>

网络配置:

<?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>

标签: c#wcfiisiis-10

解决方案


出现这个错误的原因是windows features中http激活是关闭的,你可以在control->programs and features中开启,选择“Turn Windows features on or off”,然后在你的.net framework版本中开启HTTP Activation先进的服务。

在此处输入图像描述


推荐阅读