【发布时间】:2014-03-04 20:27:19
【问题描述】:
使用 Visual Studio 2013 Premium。
目标:我在 web.config 中定义了多个 WCF 服务。为了保持 web.config 文件的可读性并使添加服务更简单,我想使用 VS2013 的 XML 转换为我的开发/生产环境的每个服务定义添加一些样板元素。
问题:我有多个<service>标签,但只有第一个被正确转换。
这是我的 Web.Config 的简化版本,其中定义了两个服务:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="AppName.AccountManagerService">
<endpoint address="AccountManagerService" binding="netTcpBinding"
bindingConfiguration="" contract="Shared.Contracts.IAccountManagerService" />
</service>
<service name="AppName.TicketManagerService">
<endpoint address="TicketManagerService" binding="netTcpBinding"
bindingConfiguration="" contract="Shared.Contracts.ITicketManagerService" />
</service>
</services>
</configuration>
我想创建一个元数据交换端点并对每个 <service> 标记执行一些其他操作(未显示)。
这是一个简化的 Web.Debug.Config,仅显示 MetadataExchange 端点:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel>
<services>
<service xdt:Locator="XPath(/configuration/system.serviceModel/services/service)">
<endpoint kind="mexEndpoint"
address="mex"
xdt:Transform="Insert()"
/>
</service>
</services>
</system.serviceModel>
</configuration>
我明白了:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="AppName.AccountManagerService">
<endpoint address="AccountManagerService" binding="netTcpBinding"
bindingConfiguration="" contract="Shared.Contracts.IAccountManagerService" />
<!-- Yay! -->
<endpoint kind="mexEndpoint"
address="mex"
/>
</service>
<service name="AppName.TicketManagerService">
<endpoint address="TicketManagerService" binding="netTcpBinding"
bindingConfiguration="" contract="Shared.Contracts.ITicketManagerService" />
<!-- Hey, where's the endpoint tag for this one? -->
</service>
</services>
</configuration>
我在xdt:Locator 属性中的XPath 参数上尝试了这些变体:
1. /configuration/system.serviceModel/services/service
2. /configuration/system.serviceModel/services//service
3. //service
所有这些都仅转换第一个<service> 部分。
我尝试将xdt:Locator 属性放在<endpoint> 标记等上,但无济于事。
我有多个 XPath 可视化工具和工具,当与上面的 XPath #1 一起使用时,它们都匹配 both <service> 标记。此外,此错误发生在“预览转换”和 Web 部署工具预览中。
我做错了什么?
(此时,我的解决方法是在我的原始 Web.Config 中包含 Mex 端点和其余调试内容,然后使用“RemoveAll()”将其删除,但这使得我的 Web.Config 真的杂乱无章,难以阅读。)
【问题讨论】:
-
这个关于stackoverflow的答案帮助了我stackoverflow.com/questions/13886291/…
标签: asp.net xml wcf web.config-transform