我想为我创建的Web服务启用WSDL检索。我可以通过我制作的.svc文件“调用”web服务:
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>
答案 0 :(得分: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>
答案 1 :(得分:1)
mex端点和httpGetEnabled看起来不错。此链接更详细地介绍了该主题,可能有用。