The client application has an app.config file where the IP address of the service is specified <endpoint address= "net. tcp://127.0.0.1:8123/Service". During development, I use 127.0.0.1 to update server references (during which the necessary classes are automatically generated).I have a few servers with wcf services for different group users. Servers have different id addresses. During click-once publishing, I have to specify the IP of and publish my application to each group. How can I configure application to be taken the ip endpoint from app.config when developing, and the ip endpoint from a saved file for user?
Asked
Active
Viewed 161 times
0
-
Use a preprocessor Directive : https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/ – jdweng Nov 16 '20 at 17:14
-
preprocessor Directive worked when app is run. Add/refresh Service Reference dont use project code, it use svcutil.exe called from studio. – EvgenOrel Nov 16 '20 at 17:39
-
Set the default option to use deploy option then override during testing to use 127.0.0.1. – jdweng Nov 16 '20 at 17:45
-
use the "add transform" option on your app.config to create a specific configuration file for each solution configuration. – martijn Nov 17 '20 at 06:18
-
Perhaps you can modify the configuration file programmatically to achieve your goal. For this link, you can refer to How to modify the configuration file programmatically: https://stackoverflow.com/questions/966323/how-to-programmatically-modify-wcf-app-config-endpoint-address-setting – Theobald Du Nov 24 '20 at 07:42
1 Answers
0
The only solution I found is to change the Endpointaddress for the client every time it connects.
string remoteIp="168.0.0.1"; // read from settings
string AuthEndPoint=string.Format("net.tcp://{0}/Auth",remoteIp)
srAuth.AuthorizeClient client = new srAuth.AuthorizeClient();
client.Endpoint.Address= new EndpointAddress(AuthEndPoint);
And then there are options - either declare a global variable, or ovverride the constructor

EvgenOrel
- 119
- 1
- 8