I have a WCF configuration file that I am trying to transform with SlowCheetah. For development use, we want to include the MEX endpoints, but when we release the product, these endpoints should be removed on all services except one. The server for which it should be left has the following endpoint:
<endpoint address="MEX"
binding="mexHttpBinding"
contract="IMetadataExchange" />
The ones that should be removed are as follows:
<endpoint address="net.tcp://computername:8001/WCFAttachmentService/MEX"
binding="netTcpBinding"
bindingConfiguration="UnsecureNetTcpBinding"
name="WCFAttachmentServiceMexEndpoint"
contract="IMetadataExchange" />
The transform I am using is:
<service>
<endpoint xdt:Locator="Condition(contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding')))" xdt:Transform="RemoveAll" />
</service>
However, when I run this, ALL MEX endpoints are removed from the config file including the one that I wish to keep. How do I make this work properly?
The
Locator
Condition expression that selects the nodes seems to be correct. If you had only the two endpoints you posted in your example, this expression will select the second endpoint.According to the documentation the
Transform
attributeRemoveAll
should "remove the selected element or elements." Based on the information you posted it's not working as expected, since the first element was not selected and was removed anyway. Based on this StackOverflow answer it seems to me that the issue is withCondition
. I'm not sure if that's a bug (it's poorly documented), but you could try some alternative solutions:1) Using
XPath
instead ofCondition
. The effective XPath expression that is applied to your configuration file as a result of theCondition
expression is:You should also obtain the same result using the
XPath
attribute instead ofCondition
:2) Using
Match
and testing an attribute such asbinding
. This is a simpler test, and would be IMO the preferred way to perform the match. You could select the nodes you want to remove by thebinding
attribute3) Using
XPath
instead ofMatch
in case you have many different bindings and only want to eliminate only those which are notmexHttpBinding
:4) Finally, you could try using several separate statements with
Condition()
orMatch()
to individually select the<endpoint>
elements you wish to remove, and usexdt:Transform="Remove"
instead ofRemoveAll
.