question

pakojonez avatar image
0 Votes"
pakojonez asked pakojonez commented

Web.Config transformations with namespaces not working

Hi all,
I have a web.config on an ASP.Net WCF .Net Framework 4.0, and I have transformations depending on the build environment.

The thing is that I have a diagnostics section inside my system.serviceModel section. On the base web.config this is empty:

 <diagnostics></diagnostics>

Then on my transformation, we apply filters which contain namespaces, like this:

 <diagnostics performanceCounters="All" xdt:Transform="Replace">
       <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="300000" maxSizeOfMessageToLog="200000000">
         <filters>
           <add xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">/s:Envelope/s:Header/a:Action[contains(.,'IMyService')]</add>
         </filters>
       </messageLogging>
     </diagnostics>

When the transformation is applied (xdt:Transform="Replace"), I get this:

 <diagnostics performanceCounters="All">
 <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
 maxMessagesToLog="300000" maxSizeOfMessageToLog="200000000">
 <filters>
 <add>/s:Envelope/s:Header/a:Action[contains(.,'IMyService')]</add>
 </filters>
 </messageLogging>
 </diagnostics>

Which causes the web.config to have an Xml error, not working properly.

Resuming, this is the current output on the filter:

 <add>/s:Envelope/s:Header/a:Action[contains(.,'IMyService')]</add>

And we would expect it to be like this:

 <add xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">/s:Envelope/s:Header/a:Action[contains(.,'IMyService')]</add>

How can I overcome this?





windows-wcf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered pakojonez commented

OK I took a look at the code. The transform tool explicitly strips out namespace attributes on elements during transformation. This is by design probably because for config files they don't make sense and could cause problems with the configuration subsystem. There isn't any case I'm aware of where you can use XML namespaces in config files since it uses a standardized format.

While testing your specific case I noticed that your filters aren't schematically valid. I can see you are using an example found in the docs but that syntax doesn't appear valid. The add member has a single attribute called filter that is the XPath string. I haven't tested which syntax is valid as I don't use WCF anymore but based upon my understanding your transform should simply be this.

<diagnostics performanceCounters="All">
    <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
 maxMessagesToLog="300000" maxSizeOfMessageToLog="200000000">
     <filters>
      <add filter="/s:Envelope/s:Header/a:Action[contains(.,'IMyService')]"></add>
 </filters>
 </messageLogging>
 </diagnostics>

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your help ;)

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered

I'm assuming your talking about the web config transforms here as you talk about your config file and build environments. If you are referring to XSD transforms instead then that would be odd to do on a config file.

You didn't post your XML transform file so we could only guess what is going wrong. However I would wager you're trying to use SetAttribute and that won't work here. In order to set attributes it must have both the attribute name and a match locator. Since you don't have that here it wouldn't be able to substitute properly. The only workaround in this case is to use the Replace transform on the filters and it'll replace everything in the root config with whatever is in the transform.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

pakojonez avatar image
0 Votes"
pakojonez answered pakojonez commented

Hi, sorry, I'm actually performing a replace transformation to the whole diagnostics element.

The problem is with the namespaces, after transforming, they are lost, which causes the web.config to become invalid...

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You haven't posted the transform file contents so we have no way of testing your code.

0 Votes 0 ·

I didn't realize, but the base element is actually empty. Updated in order to be properly explained, and added the expected output in order to be faster and easier to compare

0 Votes 0 ·