如何在web.config中使用XML Transformation更改端点地址?

Lea*_*dro 28 c# xml xslt wcf

我需要在web.config中更改此配置的地址:

<client>
  <endpoint address="OLD_ADDRESS"
    binding="basicHttpBinding"
    contract="Service.IService" name="BasicHttpBinding_IService" />
</client>
Run Code Online (Sandbox Code Playgroud)

对此:

<client>
  <endpoint address="NEW_ADDRESS"
    binding="basicHttpBinding"
    contract="Service.IService" name="BasicHttpBinding_IService" />
</client>
Run Code Online (Sandbox Code Playgroud)

在我的XML-Transformation文件中(它正在工作,它会改变另一个add key value)
我有这个:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <client>
    <endpoint name="BasicHttpBinding_IService"
      address="NEW_ADDRESS"
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </client>
Run Code Online (Sandbox Code Playgroud)

但它不起作用.如果我按名字找到,我不明白为什么它不会改变.任何帮助/提示都将被预先确定.谢谢

kal*_*hir 50

转换文件的结构是否与您的web.config相匹配?具体来说,您是否缺少systems.serviceModel元素?

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
   <system.serviceModel>
      <client>
         <endpoint name="BasicHttpBinding_IService" address="NEW_ADDRESS"
           xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
      </client>
   </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

  • 当然,谢谢.我想我需要更多咖啡 (4认同)