2

I recently created a Powershell script that deploys my Web Application (ASP.NET MVC) to Azure. It works like it should, but I figured out that it would improve the script a lot by being able to change the endpoint in the Web.config file during deployment, i.e. the script prompts the user for the address. The Web.config section looks like this:

<system.serviceModel>
    <client>
      <endpoint address="http://localhost:10421/MyService" binding="binding" bindingConfiguration="foo" contract="bar" name="id" />
    </client>
</system.serviceModel>

I would like to change the endpoint address with my script.

1 Answer 1

2

Use the Get-Content cmdlet to load your configuration file, access the property and change it and finally write it back using the Set-Content cmdlet:

[xml]$content = (Get-Content 'your_file')
$content.configuration.'system.serviceModel'.client.endpoint.address = 'YourNewAdress'
$content | Set-Content 'your_file'

Note: I asume that the system.serviceModel is within the configuration node. If not, omit that.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Martin for the answer. I will try it and get back to you shortly. But won't this override the file itself?, i.e. this is just a way to edit the address, but then I'll have to build the project to deploy. So in the end this is the same way as just editing the endpoint myself with the desired address -> deploy -> revert the address back to "localhost:10421/MyService"?
@DKo Yes, it will just override the file itself. You could also bootstrap WCF endpoints programmatically in C#, maybe you are looking for that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.