简体   繁体   中英

Xdt Transform To Add Security Mode to multiple bindings

My web application makes use of multiple web services, so I have bindings to each of them, like this:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_ICityDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
      </binding>
      <binding name="BasicHttpBinding_IBuildingDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
      </binding>
      <binding name="BasicHttpBinding_IEventDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
      </binding>
      ...
    </basicHttpBinding>
  </bindings>

On my development environment, I cannot use SSL (and do not need it), but when I go to deploy, I have to use SSL, so I need to add a security mode to each of those bindings. I applied the following XDT transform:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding>
        <security mode="Transport" xdt:Transform="Insert">
          <transport clientCredentialType="None" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>

But that only adds the security mode to the first binding. But even after reading the XDT Transform documentation and a number of articles and SO question/answers, I cannot figure out how to specify a locator that will select all the bindings so that child node gets added to all of them. I could specify each of the bindings by name, but that seems clunky. Any ideas?

As far as I know, what you want to achieve (ie inserting new element on multiple elements) is not supported by XDT transformations, which is a pity!

One way to workaround the problem might be to add the security node to all your bindings for your development environment and set it to None .

You can then have some global replacements to update all attributes to Transport

Your web.config should be something like

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_ICityDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
        <security mode="None">
          <transport clientCredentialType="None" />
        </security>
      </binding>
      <binding name="BasicHttpBinding_IBuildingDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
        <security mode="None">
          <transport clientCredentialType="None" />
        </security>
      </binding>
      <binding name="BasicHttpBinding_IEventDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
        <security mode="None">
          <transport clientCredentialType="None" />
        </security>
      </binding>
      </basicHttpBinding>
  </bindings>
</system.serviceModel>

And your XDT transform should be like

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <!-- Define Global Replacements -->
  <replaceAll>
      <WCF_replaceBindingSecurityMode xdt:Locator="XPath(//basicHttpBinding/binding/security)" xdt:Transform="SetAttributes(mode)" mode="Transport" />
  </replaceAll>

</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM