locked
Make a c# consol app use proxy server settings RRS feed

  • Question

  • Hi

    We are planning to wrote a c# consol application that needs to call out to some web services on the internet (both a WSDL SOAP web service and a RESTful web service).

    This c# app will live on a server - and run using a service account. This service account thus needs to be able to access the internet - but internet access is normally via a proxy server

    i.e. we want to force the App to use a proxy server (and supply the proxy server name/port as parameters to the app) - but how do we do this ? Do we need to use a third party library.... and if so is there one that's reccomended ?

    Currently using Visual Studio 2015.

    A) For the wsdl web service, we are using a service reference...

    using servicevar = mynamespace.myservice;

    client = new ....

    client.Open

    myservicereference.somestructure[] resp;

    resp = client.somewebservice(some parameter); 

    B) for the RESTful web service.... code is like this

                    WebRequestHandler handler = new WebRequestHandler()
                    {
                        CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
                    };
                    using (HttpClient client = new HttpClient(handler))
                    {
                        string stringPayload = JsonConvert.SerializeObject(payload);
                       
                        System.Net.Http.HttpContent httpContent  = new StringContent(stringPayload, Encoding.UTF8, "application/x-www-form-urlencoded");
                     
                        string URL1 = ConfigurationManager.AppSettings["URL1"];
                        var httpResponse = await client.PostAsync(URL1, httpContent);

    Thanks

    Greg



    • Edited by goofygdog2 Tuesday, September 18, 2018 3:18 PM
    Tuesday, September 18, 2018 2:21 PM

Answers

  • Have you seen the following?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by goofygdog2 Thursday, September 20, 2018 8:00 AM
    Tuesday, September 18, 2018 11:10 PM

All replies

  • Have you seen the following?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by goofygdog2 Thursday, September 20, 2018 8:00 AM
    Tuesday, September 18, 2018 11:10 PM
  • Check following article might it will help you to set proxy details in c# console app.

    https://stackoverflow.com/questions/1938990/c-sharp-connecting-through-proxy


    Regards

    Tutlane.com


    Wednesday, September 19, 2018 1:51 PM
  • Normally proxy settings are controlled by your network team and is managed by the user profile that is running. So, for example, IT users have Internet access but the janitor doesn't. In this case all you need to do is use the correct user account and you're fine. You don't need to explicitly configure a proxy unless you're having issues. Are you having issues?

    Note that services typically run under an account that cannot access the network. You'll need to ensure the account the service runs under has network access (NETWORK SERVICE, domain account, etc).


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, September 19, 2018 2:45 PM
  • Thanks for that

    Will give the config file settings method a go.

    Thursday, September 20, 2018 8:06 AM