针对behaviorConfiguration属性的Web配置转换不起作用

时间:2016-03-21 15:56:06

标签: web.config-transform

Web.config原创

 <service behaviorConfiguration="Test.DevelopmentPc.Environment.Behavior" name="Tks.Licensing.Service.ActivationServer">
    <endpoint address="" name="httpEndpoint" binding="basicHttpBinding" bindingConfiguration="testBasicHttpBinding" contract="Tks.Licensing.Contracts.ServiceContract.IActivationService"/>
    <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint" contract="IMetadataExchange"/>
  </service>

我想要的是什么

<service behaviorConfiguration="__BehaviorConfiguration__" name="Tks.Licensing.Service.ActivationServer">
  <endpoint address="" binding="wsHttpBinding" bindingConfiguration="secureWsHttpBinding" name="httpEndpoint" contract="Tks.Licensing.Contracts.ServiceContract.IActivationService">
    <identity>
      <dns value="__ServerIdentity__"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint" contract="IMetadataExchange" />
</service>

这是我已经尝试过的:

<service behaviorConfiguration="__BehaviorConfiguration__" name="Tks.Licensing.Service.ActivationServer" xdt:Transform="SetAttributes(behaviorConfiguration)" xdt:Locator="Match(name)">
  <endpoint address="" binding="wsHttpBinding" bindingConfiguration="secureWsHttpBinding" name="httpEndpoint" contract="Tks.Licensing.Contracts.ServiceContract.IActivationService">
    <identity xdt:Trasform="Insert">
      <dns value="__ServerIdentity__"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint" contract="IMetadataExchange" />
</service>

原始网络配置根本没有变化。

原始网站中有多个服务块,名称不同。 我不允许对原始配置文件进行任何更改。有没有办法在不触及原始文件的情况下执行此操作?

1 个答案:

答案 0 :(得分:0)

我通过替换整个“服务”元素来实现它。

<services xdt:Transform="Replace">
<service behaviorConfiguration="__BehaviorConfiguration__" name="Tks.Licensing.Service.ActivationServer">
  <endpoint address="" binding="wsHttpBinding" bindingConfiguration="secureWsHttpBinding" name="httpEndpoint" contract="Tks.Licensing.Contracts.ServiceContract.IActivationService">
    <identity>
      <dns value="__ServerIdentity__"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint" contract="IMetadataExchange" />
</service></services>