Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change an endpoint address with XML Transformation in web.config?

Tags:

c#

xml

wcf

xslt

I need change the address of this configuration in a web.config:

<client>   <endpoint address="OLD_ADDRESS"     binding="basicHttpBinding"     contract="Service.IService" name="BasicHttpBinding_IService" /> </client> 

to this:

<client>   <endpoint address="NEW_ADDRESS"     binding="basicHttpBinding"     contract="Service.IService" name="BasicHttpBinding_IService" /> </client> 

In my XML-Transformation file (it's working, it changes another add key value)
I have this:

<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> 

but it doesn't work. I don't understand why it doesn't change, if I locate by name. Any help/tip will be preciated. Thanks

like image 878
Leandro Bardelli Avatar asked Nov 12 '14 18:11

Leandro Bardelli


People also ask

How do I create a new transformation in web config?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

What is Xdt transform in web config?

A transform file is an XML file that specifies how the Web. config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix.

How does web config transform work?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.


1 Answers

Does the structure of your transformation file match your web.config? Specifically, are you missing a systems.serviceModel element?

<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> 
like image 183
kalthir Avatar answered Sep 24 '22 09:09

kalthir