【问题标题】:Transforming a specific node in a web.config转换 web.config 中的特定节点
【发布时间】:2011-03-30 03:57:15
【问题描述】:

我想使用 VS2010 web.config 转换功能,但我不确定应该使用 XPath 来替换某个值。

我定义了以下客户端服务端点:

<client>
    <endpoint   name="IMyService"
                address="net.tcp://x.x.x.x:xx/MySvc"
                binding="netTcpBinding"
                bindingConfiguration="..."
                contract="..."
                >
        <identity>
            <servicePrincipalName value="host/testMachine.domain.com" />
        </identity>
    </endpoint>
</client>

我想用以下值替换servicePrincipalName 节点。

<servicePrincipalName value="host/productionMachine.domain.com" />

由于可能定义了多个客户端端点,我更喜欢使用标识特定端点节点的 XPath(在这种情况下,name="IMyService")。

所以在伪代码中,我需要这样做:

<servicePrincipalName value="host/productionMachine.domain.com" 
                      xdt:Transform="Replace" 
                      xdt:Locator="Condition([containing endpoint node] @name='IMyService')" 
                      />

有人能告诉我这些方括号在哪里,或者告诉我一些其他时髦的方法来替换那个特定的节点吗?

【问题讨论】:

    标签: visual-studio-2010 web-config transformation


    【解决方案1】:

    我会匹配并替换端点节点,如下:

    <client>
        <endpoint name="IMyService"
                address="net.tcp://x.x.x.x:xx/MySvc"
                binding="netTcpBinding"
                bindingConfiguration="..."
                contract="..."
                xdt:Transform="Replace"
                xdt:Locator="Match(name)"
                >
            <identity>
                <servicePrincipalName value="host/productionMachine.domain.com" />
            </identity>
        </endpoint>
    </client>
    

    【讨论】:

    • 谢谢,过几天我可以测试一下(这里是周末),我会告诉你进展如何。
    猜你喜欢
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 2012-05-10
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多