1

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?

helderdarocha
  • 23,209
  • 4
  • 50
  • 65
Dirk Dastardly
  • 1,017
  • 2
  • 12
  • 23
  • Considering the example you posted, that looks like a bug. Placing both `endpoints` in an XML file, and using the expression `//endpoint[contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding'))]` only selects the larger one. – helderdarocha Jun 12 '14 at 15:55
  • You could try an alternative match: If the `binding` attribute *always* contains an exact string, you could avoid using `contains()` and use `not(@binding='mexHttpBinding')` or `@binding != 'mexHttpBinding'`. – helderdarocha Jun 12 '14 at 15:55
  • I added [tag:xdt] and [tag:xdt-transform] tags which should help attract users who use the tool. – helderdarocha Jun 19 '14 at 12:46
  • Also @SayedIbrahimHashimi might be able to help on this. – helderdarocha Jun 19 '14 at 12:51

1 Answers1

0

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 attribute RemoveAll 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 with Condition. I'm not sure if that's a bug (it's poorly documented), but you could try some alternative solutions:

1) Using XPath instead of Condition. The effective XPath expression that is applied to your configuration file as a result of the Condition expression is:

/services/service/endpoint[contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding'))]

You should also obtain the same result using the XPath attribute instead of Condition:

<endpoint xdt:Locator="XPath(/services/service/endpoint[contains(@address, 'MEX') 
                             and not(contains(@binding, 'mexHttpBinding'))])" xdt:Transform="RemoveAll" />

2) Using Match and testing an attribute such as binding. 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 the binding attribute

<endpoint binding="netTcpBinding" xdt:Locator="Match(binding)" xdt:Transform="RemoveAll" />

3) UsingXPath instead of Match in case you have many different bindings and only want to eliminate only those which are not mexHttpBinding:

<endpoint xdt:Locator="XPath(/services/service/endpoint[not(@binding='mexHttpBinding'))" xdt:Transform="RemoveAll" />

4) Finally, you could try using several separate statements with Condition() or Match() to individually select the <endpoint> elements you wish to remove, and use xdt:Transform="Remove" instead of RemoveAll.

Community
  • 1
  • 1
helderdarocha
  • 23,209
  • 4
  • 50
  • 65
  • While I appreciate your input, none of the three examples got me where I need to be. I also tried: And got the same effect, like it ignored the condition in the service and just met the condition in the endpoint. – Dirk Dastardly Jun 19 '14 at 11:27
  • 1
    I understand. I was actually not able to reproduce your problem. I set up a minimal environment and the transforms worked as expected. It might be something else. Perhaps you could setup a minimal example yourself (small enough that you could post the full files here) and, if you don't discover the error in the process, update your question with more details. You could also post an issue here: https://github.com/sayedihashimi/slow-cheetah/issues?page=1&state=open – helderdarocha Jun 19 '14 at 12:44