none
Using the system web proxy when calling dynamic Web Service RRS feed

  • Question

  • Hi all,

    This may be a simple question, but I am sort of new to programming with C# and web services. Please excuse me if I am repeating a question. I was unable to find answers to my questions after extensive searches.

    I am calling an ASMX web service over SOAP from a C# application (it's an outlook COM add-in - so I presume in the context of these questions it can be the same as a winForms application). While it works perfectly on my dev and QA environments, the client has a proxy setup in their office network. As a temporary solution we have created an outlook.exe.config file for the user with the <defaultProxy enabled="true" useDefaultCredentials="true"> code. This seems to work without issues.

    1. I want to know if this I can replace this config file entry with setting the web service's proxy and proxy.Credentials values to the system web proxy (see code below).
    2. My web services are dynamic, that is, the URL will be set during runtime. What is the order to set the proxy values? Before or after setting the URL?

    MyWebService.Service1 _myWService = new MyWebService.Service1();

    _myWService.Proxy = System.Net.HttpWebRequest.GetSystemWebProxy(); _myWService.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

    _myWService.Url = GetWServiceURL(); //Gets the appropriate url //the url is always randomized by adding a random numeric value as a query parameter "?rnd=xxxxxx"

    DataTable x = _myWService.GetDetails();

    OR

    MyWebService.Service1 _myWService = new MyWebService.Service1();
    
    _myWService.Url = GetWServiceURL(); //Gets the appropriate url
    //the url is always randomized by adding a random numeric value as a query parameter "?rnd=xxxxxx"
    _myWService.Proxy = System.Net.HttpWebRequest.GetSystemWebProxy();
    _myWService.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    DataTable x = _myWService.GetDetails();

    Any help and pointers are appreciated! Thanks!

    Cheers,

    Thimila

    • Moved by Bob Shen Wednesday, May 22, 2013 9:27 AM
    Tuesday, May 21, 2013 5:11 AM

Answers

  • Other then having to set it before opening the connection, it should have no relevancy when you do it.

    Everything before the open() is just manipulating strings.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Wednesday, May 22, 2013 9:13 AM

All replies

  • Generally proxy settings should be defined on Operation system level, not on programm level. Programm  level proxy settings should only be used if they differ from the OS settings, wich should generally not be the casse.
    Programm settings overwrite system settings, but system settings are used by default.

    Afaik SOAP works usually over using the HTTP or TCP protocoll for actuall network traffic. If you have a HTTP proxy it should propably be set on system level (Systemsettings, Internetoptions, Connections). That way all HTTP usign programms (all webbrowsers, SOAP over HTTP) will get the right settings.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Tuesday, May 21, 2013 1:43 PM
  • Hi Christopher,

    Thanks for the reply.

    The user has their proxy settings set on their InternetOptions already. But I found out the hard way that unless there is the

    <system.net>
        <defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
    </system.net>

    line on the app's config file, my calls to the web service will fail as they don't use the proxy settings.

    I read somewhere that you can set this programmatically using the following code, and NOT have it on the config file.

    _myWService.Proxy = System.Net.HttpWebRequest.GetSystemWebProxy();
    _myWService.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

    I just wanted to confirm that this is true. And if so, what is the order that I have to set it: before or after setting the web service's URL (code examples in my original post)? Or is there no impact by the order it is set?

    Cheers,

    Thimila

    Wednesday, May 22, 2013 12:48 AM
  • Other then having to set it before opening the connection, it should have no relevancy when you do it.

    Everything before the open() is just manipulating strings.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Wednesday, May 22, 2013 9:13 AM
  • Thanks Christopher!
    Thursday, May 23, 2013 11:27 PM