By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

Programatically change Endpoint Address in App.config

maylortaylor
P: 72
I have a pretty simple TimeClock application written in VB (.net4) that I'm trying to add to. The addition will allow the user to change where the service is coming from.

In short, I want to be able to programatically change the Endpoint Address in the App.Config file.

For reference:
Expand|Select|Wrap|Line Numbers
  1. <client>
  2.         <endpoint address="net.tcp://localhost:8090/MyService/TimeClockService"
  3.                   binding="netTcpBinding" 
  4.                   contract="TimeClockService.ITimeClock" 
  5.                   name="tcpBinding">
  6.             <identity>
  7.                 <userPrincipalName value="susnick-PC\susnick" />
  8.             </identity>
  9.         </endpoint>
  10.     </client>
The only part i'm really trying to change is the 'address'.

So far, this is what I have.

Expand|Select|Wrap|Line Numbers
  1. Private Sub currentIP_TextChanged_1(sender As Object, e As EventArgs) Handles currentIP.TextChanged
  2.         Dim proxy As New TimeClockService.TimeClockClient
  3.         Dim curAddress As String
  4.  
  5.         curAddress = proxy.Endpoint.Address.ToString
  6.         currentIP.Text = curAddress
  7.  
  8.     End Sub
  9.  
  10.     Private Sub changeIP_Click(sender As Object, e As EventArgs) Handles changeIP.Click
  11.         Dim newAddress As String
  12.         newAddress = "http://" & newIP.Text & "/"
  13.  
  14.         Dim client As New TimeClockService.TimeClockClient
  15.         client.Endpoint.Address = New EndpointAddress(New Uri(newAddress), client.Endpoint.Address.Identity, client.Endpoint.Address.Headers)
  16.  
  17.  
  18.         currentIP.Text = newAddress
  19.         MsgBox("Current IP has changed to " & newAddress)
  20.     End Sub
The code seems to be doing what I want it to do (which is change the EndpointAddress to the IP of my choosing.) However, when the changeIP_click sub gets to the part where it assigns the newAddress to the currentIP text box...it reruns the currentIp sub routine and, in doing so, changes the address back to the original address.

Is there any guiding wisdom to help me solve this?

For the record, i know that this is not something you normally would change programatically but my bossman says he wants this functionality --- so, please help.
Jan 7 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.