【发布时间】:2023-03-31 00:29:02
【问题描述】:
我正在学习 IIS 中的 WCF 部署,我发现了一些奇怪的东西。基本上,无论我如何在 web.config 中设置元素的 behaviorConfiguration 属性,我的服务都只使用默认行为。
这是我的 web.config 的相关部分:
<system.serviceModel>
<services>
<service name="TableImport" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="wsHttpBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false" />
</behavior>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
如您所见,默认 serviceMetadata 元素具有 httpGetEnabled="false",而 MyServiceTypeBehaviors serviceMetadata 元素具有 httpGetEnabled="true"。您还可以看到我的服务的 behaviorConfiguration 属性设置为“MyServiceTypeBehaviors”。
结果应该是我的服务发布了元数据,但是通过浏览器和 Visual Studio“添加服务引用”功能我得到了相同的结果:没有元数据。
另一方面,如果我在默认行为中启用元数据并在“MyServiceTypeBehaviors”中禁用它并继续让我的服务使用 MyServiceTypeBehaviors,那么我会通过浏览器和 VS 获取元数据。
对我来说,这些测试表明我的服务使用默认行为,无论我如何设置我的配置文件......但同时我可以通过 web.config 更改默认行为,所以我的 web.config 实际上能够影响服务的工作方式。有什么想法吗?
【问题讨论】:
-
如果删除默认行为会发生什么?你的具体行为是否正确?
-
如果我删除默认行为并且只有 MyServiceTypeBehaviors 和 MyServiceTypeBehaviors 启用元数据,结果是没有元数据。所以我的评估是删除默认行为并不能使我的特定行为正常工作。
-
我会尝试删除默认的 behsvior 和策略版本。
标签: wcf iis web-config servicebehavior