tags:

views:

696

answers:

4

If I have the following setting in my app.config file. It is a setting I need to make sure my WCF client can negotiate the default proxy server.

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

Unfortunately, I can't add to the app.config file in my environment. How do I ensure these settings by setting them at runtime?

A: 

Whatever the defined name of your executable (not a library dll) assembly is, add a ".config" at the end...

so if your executable is to be

AcmeWidgets.EastCoast.MyApplicationName.exe

Then the app.config will get renamed to

AcmeWidgets.EastCoast.MyApplicationName.exe.config

However, I wouldn't recommend you attempt to dynamically change these settings (in the config file on disk) at runtime...

instead, can you code your app so that it instead populates and uses static variables from these config settings... and then implement the dynamic "change the value" functionality so that it changes these static variables...

This way you can still "affect" the runtime behavior dynamically, but avoid the hassle of writing to the config file, and Ops management can manage the "default" values in the config file by editing it...

Charles Bretana
I don't have access to the .exe. I am a reusable DLL. The DLL is hosted in the browser. I don't have access to the app.config file.
Brian Genisio
Dlls do not have config files... the config file is one per Operating system Process... and there is one and only one process per executable. Each application that uses your dll will have it's own config file, with a different name.
Charles Bretana
Can you use the Application settings functionality for this? (It's in the dll's Project Proprties screen, Settings tab)
Charles Bretana
A: 

I think what you do is create a System.Net.WebProxy object, then set the appropriate variables, then set the System.Net.WebRequest.DefaultWebProxy:

System.Net.WebProxy proxy = new WebProxy();
proxy.UseDefaultCredentials = true;
WebRequest.DefaultWebProxy = proxy;

This post sort of talks about the whole thing: Link

Hope that helps!

Zachary Yates
This is not a WCF solution, is it? How do I create a WCF client proxy with the default creds?
Brian Genisio
This moved my problem. Now, I get: "TCP error code 10061: No connection could be made because the target machine actively refused it". Unfortunately, there is nothing wrong with the service.
Brian Genisio
A: 

On the properties page for your project there should be a settings tab. Anything you put there actually lives in a *.settings file in the project, but will also be included in the app.config file automatically at deployment. Can you make changes there?

Joel Coehoorn
No, I am a reusable DLL. I don't get to use app.config.
Brian Genisio
A: 

I imagine that you are using a binding that inherits from WSHttpBindingBase. If so, you can also try setting the 'UseDefaultWebProxy' property in code. Something like this:

myWSHttpBinding.UseDefaultWebProxy = True;

Edit: BasicHttpBinding also has the same property.

Mitch Baker
No, that doesn't do it. It goes to the proper proxy, but doesn't use the default credentials. Fails with a 407 Authentication failure
Brian Genisio