我有一个WCF配置文件,我正在尝试用SlowCheetah进行转换。对于开发用途,我们希望包括MEX端点,但是当我们发布产品时,除了一个以外,所有服务上都应该删除这些端点。应该为其保留的服务器具有以下端点:
<endpoint address="MEX"
binding="mexHttpBinding"
contract="IMetadataExchange" />应予删除的部分如下:
<endpoint address="net.tcp://computername:8001/WCFAttachmentService/MEX"
binding="netTcpBinding"
bindingConfiguration="UnsecureNetTcpBinding"
name="WCFAttachmentServiceMexEndpoint"
contract="IMetadataExchange" />我正在使用的转换是:
<service>
<endpoint xdt:Locator="Condition(contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding')))" xdt:Transform="RemoveAll" />
</service>但是,当我运行这个命令时,所有MEX端点都会从配置文件中删除,包括我希望保留的那个。我怎样才能使它正常工作呢?
发布于 2014-06-19 05:21:59
选择节点的Locator条件表达式似乎是正确的。如果只有在示例中张贴的两个端点,则该表达式将选择第二个端点。
根据文档,Transform属性RemoveAll应该“删除所选的元素”。根据您发布的信息,它不能像预期的那样工作,因为第一个元素没有被选中,而且已经被删除。基于这个StackOverflow的答案,在我看来,问题在于Condition。我不确定这是否是一个bug (它的文档很少),但是您可以尝试一些替代的解决方案:
1)使用XPath代替Condition。作为XPath表达式的结果应用于配置文件的有效Condition表达式是:
/services/service/endpoint[contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding'))]您还应该使用XPath属性而不是Condition获得相同的结果。
<endpoint xdt:Locator="XPath(/services/service/endpoint[contains(@address, 'MEX')
and not(contains(@binding, 'mexHttpBinding'))])" xdt:Transform="RemoveAll" />2)使用Match并测试属性(如binding )。这是一个简单的测试,并将是国际海事组织进行比赛的首选方式。可以通过binding属性选择要删除的节点。
<endpoint binding="netTcpBinding" xdt:Locator="Match(binding)" xdt:Transform="RemoveAll" />3)如果您有许多不同的绑定,并且只想消除那些不是XPath的绑定,则使用Match代替mexHttpBinding
<endpoint xdt:Locator="XPath(/services/service/endpoint[not(@binding='mexHttpBinding'))" xdt:Transform="RemoveAll" />4)最后,可以尝试在Condition()或Match()中使用几个单独的语句来单独选择要删除的<endpoint>元素,并使用xdt:Transform="Remove"而不是RemoveAll。
https://stackoverflow.com/questions/24126008
复制相似问题