WCF 服务库 (IIS):当前禁用此服务的元数据发布
WCF Service Library (IIS): Metadata publishing for this service is currently disabled
我收到这个错误,我无法摆脱它。这个问题类似于 this SO 问题和许多其他问题,更不用说页面本身了。
是的,我完全知道 namespace
和 service name
必须完全匹配。我现在读了无数次。
我有一个 WCF 服务库,我在 IIS 中 运行。服务器是 Windows Server 2016 标准版。我将 App.config
重命名为 Web.config
,尽管我尝试使用 App.config
。我尝试了每一个似乎不计其数的配置,但仍然是同样的错误。是的,我尝试添加绑定并指定 basicHttpBinding
.
Web.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyTesterLibrary.MyTester" behaviorConfiguration="MetadataBehavior">
<endpoint address="" binding="wsHttpBinding" contract="MyTesterLibrary.IMyTester" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
主要Class
namespace MyTesterLibrary
{
public class MyTester : IMyTester
{
public string GetVersionInfo()
{
Backup.GetVersionInfo(out string response);
return response;
}
}
}
界面Class
namespace MyTesterLibrary
{
[ServiceContract]
public interface IMyTester
{
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/GetVersionInfo")]
[OperationContract]
string GetVersionInfo();
}
}
ProductServiceHost.svc
<%@ ServiceHost Service="MyTesterLibrary.MyTester" %>
我按照另一个站点上的说明创建了 IIS 站点。这张截图说明了一切。
我知道在引用的 SO 文章中,那个人坚持认为问题出在 IIS 中,但事实并非如此,但我的问题确实如此。我刚刚又试了一次 basicHttpBinding
,还是一样。
asp.net 论坛上的 This question 也很有趣。我本能地将 App.config
重命名为 Web.config
并重建了 DLL。 IIS 不读取“App.config”。
想法?
最后引用的那篇文章说明了问题所在,我的怀疑是正确的。我把这个问题留在这里,因为我写得很好,但更重要的是没有说明一个重要的事实。
Visual Studio
或 C#
未嵌入 Web.config 或 IIS 未从 DLL 中提取文件。我看过的所有文章都说写一个SVC文件,把DLL放在bin文件里,但是都漏掉了两个关键的信息。
将App.config
复制到`Web.config'。
将 Web.config
的副本放在与 SVC 文件相同的文件夹中。
在IIS中无需刷新网站,但需要刷新浏览器页面。
我希望这个答案能帮助到别人,因为我真的很痛苦,几乎没有得到它。
我收到这个错误,我无法摆脱它。这个问题类似于 this SO 问题和许多其他问题,更不用说页面本身了。
是的,我完全知道 namespace
和 service name
必须完全匹配。我现在读了无数次。
我有一个 WCF 服务库,我在 IIS 中 运行。服务器是 Windows Server 2016 标准版。我将 App.config
重命名为 Web.config
,尽管我尝试使用 App.config
。我尝试了每一个似乎不计其数的配置,但仍然是同样的错误。是的,我尝试添加绑定并指定 basicHttpBinding
.
Web.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyTesterLibrary.MyTester" behaviorConfiguration="MetadataBehavior">
<endpoint address="" binding="wsHttpBinding" contract="MyTesterLibrary.IMyTester" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
主要Class
namespace MyTesterLibrary
{
public class MyTester : IMyTester
{
public string GetVersionInfo()
{
Backup.GetVersionInfo(out string response);
return response;
}
}
}
界面Class
namespace MyTesterLibrary
{
[ServiceContract]
public interface IMyTester
{
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/GetVersionInfo")]
[OperationContract]
string GetVersionInfo();
}
}
ProductServiceHost.svc
<%@ ServiceHost Service="MyTesterLibrary.MyTester" %>
我按照另一个站点上的说明创建了 IIS 站点。这张截图说明了一切。
我知道在引用的 SO 文章中,那个人坚持认为问题出在 IIS 中,但事实并非如此,但我的问题确实如此。我刚刚又试了一次 basicHttpBinding
,还是一样。
This question 也很有趣。我本能地将 App.config
重命名为 Web.config
并重建了 DLL。 IIS 不读取“App.config”。
想法?
最后引用的那篇文章说明了问题所在,我的怀疑是正确的。我把这个问题留在这里,因为我写得很好,但更重要的是没有说明一个重要的事实。
Visual Studio
或 C#
未嵌入 Web.config 或 IIS 未从 DLL 中提取文件。我看过的所有文章都说写一个SVC文件,把DLL放在bin文件里,但是都漏掉了两个关键的信息。
将
App.config
复制到`Web.config'。将
Web.config
的副本放在与 SVC 文件相同的文件夹中。
在IIS中无需刷新网站,但需要刷新浏览器页面。
我希望这个答案能帮助到别人,因为我真的很痛苦,几乎没有得到它。