Click here to Skip to main content
15,879,490 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I created a Rest web API and now I want to call the operations exposed by the API from a Proxy. My environment is Visual Studio, C#.

As the operations that I exposed in the API share a part of the URL/endpoint ("api/NameOfTheController"), I want to refer to this piece of URL by creating a custom tag in the app.config file of the Proxy project; I'm gonna call it by using ConfigurationManager to initialize a property of the Proxy.

How should I use the ConfigurationManager class to call the value of the custom tag?

What I have tried:

In the app.config of the proxy I wrote thee following tag, inside the <client> tag:
<customEndpointSegment name = "/api/NameOfTheController" />

Inside the same <client> tag there is a <endpoint> tag which points to another different service too.


In the Proxy.cs I have the following:
string webApiEndpoint;
HttpClient client;

public RestProxy()
{
   webApiEndpoint = ConfigurationManager. // I have to call the value of the tag here
   client = new HttpClient();
   client.BaseAddress = webApiEndpoint;
}
Posted
Updated 23-Nov-20 18:49pm

1 solution

customEndpointSegment does not appear to be a standard configuration element - the only match in Google is this question.

You have presumably written your own configuration section to handle this element. You will need to use that section to read the configuration value.

We can't tell you how, because we can't see your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900