【发布时间】:2021-03-17 11:06:14
【问题描述】:
我正在使用 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" %>
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>
【问题讨论】: