locked
How to override proxy settings for an App

    Întrebare

  • Hello Folks,

    .NET3.5SP1, C#2008

    I am writing a cs program to use a vendor's SDK and API library. They have supplied me a dll with all their routines and I have compiled my application. It uses an app.config file too. The problem is that I have to interface to a web service via my proxy server and I am not sure how to force .NET to use my proxy server and it also requires credentials. I DO NOT want to use local browser settings.

    Here is the app.config file:

    [code]

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
       <appSettings>
          <add key="Url" value="https://rserver/webservice"/>
       </appSettings>
       <system.net>
       <defaultProxy enabled="true" useDefaultCredentials="false">
       <proxy proxyaddress="http://superproxy:80/"/>
       </defaultProxy>
       </system.net>
    </configuration>

    [/code]

    Since I do not have access to the creating of the httpWebRequest instance (this is done in the dll) how do I tell .NET what the proxy credentials (username, password) are? Using this App.config is definitely overriding the proxy as I can see in a packet capture using Wireshark - it is routing to superproxy and not the proxy that is configured in my browser - which is the desired effect BUT need to know how to send those credentials as it returns 407 proxy authentication error.

    Thanks for your help!



    • Editat de fmSTYX 15 februarie 2012 20:23
    15 februarie 2012 19:17

Toate mesajele

  • Since you're writing libraries, I think your code should follow what the web browser told your library about proxy. Or you'll have to deal with cases where the web service cannot be connected in the future.

    The correct way to address this issue is to tell the customer side admins to add "the server hosting your webservice" into the proxy override list in IE option -> connection -> proxy setting -> advanced. Alternatively you can put the setting there yourself by writing ProxyOverride key as stated in here. Note that you may have to tell the user to logout and relogin for this setting to put in effect.

    16 februarie 2012 02:34
  • The programs needs to be run from a production WIN2008 server - we do not want to use local settings or browser settings. We need to explicitly tell the app what proxy to use and what they credentials are.
    16 februarie 2012 13:33
  • In that case, you may just expose <yourWebServiceObject>.Proxy to the application code and let them worry about it. Include in the documentation that if they want to inherit the IE's proxy setting, they should set it to System.Net.WebRequest.DefaultWebProxy.
    17 februarie 2012 02:42
  • The problem is the vendor's SDK isn't "proxy aware" and that I don't have their source code for their DLL where they generate the http request object (Webservice using SOAP calls). This app.config has helped me by forcing the traffic to the right proxy server but no credentials are being sent so the proxy returns a 407 anauthorized:

    <system.net>
       <defaultProxy enabled="true" useDefaultCredentials="false">
       <proxy proxyaddress="http://superproxy:80/"/>
       </defaultProxy>
       </system.net>

    My question is how do I tell .NET what credentials to use? I do not want to use IE local settings. I need to specifically tell .NET what those credentials are.

    17 februarie 2012 14:04
  • I think you need to specify a <module /> element that points to your class implementing IWebProxy class (this is just a information containing class, just implement the members to return required information would be okay), then your class will read from the config file in the constructor to get the values to return.
    • Editat de cheong00 18 februarie 2012 02:11
    18 februarie 2012 02:11
  • Hmmm....

    :)

    I will look into that and see if I can resolve this using that solution!

    24 februarie 2012 16:48