2

I am trying to connect to a URI pointing to a WSDL file which describes a WCF service by using the MetadataExchangeClient class.

var mexClient = new MetadataExchangeClient(uri, MetadataExchangeClientMode.HttpGet);
var metaDocs = mexClient.GetMetadata();

The problem is that I cannot access this uri directly and need to go through a HTTP proxy server. The proxy server URL can change at runtime so I cannot simply configure it through the app.config file.

Where can I specify the proxy server information in the MetadataExchangeClient class?

Anyone got an idea? WCF experts?

Wolfgang Ziegler
  • 1,617
  • 11
  • 23

2 Answers2

3

You need to specify the proxy in the app.config like this:

<system.net>
  <defaultProxy enabled="true">
   <proxy bypassonlocal="true"
          proxyaddress="http://proxy.domain.org:8888/" />
  </defaultProxy>
</system.net>
albertjan
  • 7,411
  • 5
  • 39
  • 70
  • Sorry, I forgot to mention that proxy data (url, credentials) is configured at runtime. So I cannot hardcode it in `app.config`. (I updated the question). – Wolfgang Ziegler Jul 25 '12 at 10:17
  • Could you include that code in question? Do you do it like [this](http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy-credentials-in-your-web-config) – albertjan Jul 25 '12 at 10:21
  • In my application the user can configure a proxy at runtime. Based on that, I have to disable the default proxy and use the newly specified proxy settings. I have to pick up these new settings immediately. Restarting the application is not an option. – Wolfgang Ziegler Jul 25 '12 at 12:26
  • Do you update the system proxy when the user updates the proxy? How do you set the proxy? – albertjan Jul 25 '12 at 12:28
  • No, the system proxy is not updated. The system proxy is the default, but the user can specify a custom proxy, which is just valid for the application. – Wolfgang Ziegler Jul 25 '12 at 12:34
  • Do you use something like this: [click here!](http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy-credentials-in-your-web-config) to update the proxy? – albertjan Jul 25 '12 at 12:37
  • Thx, you posted that URL before. But how does that handle the switch from system proxy to the "manually" configured one? – Wolfgang Ziegler Jul 25 '12 at 12:44
  • You can let `IsBypassed` return `false` or `true`. – albertjan Jul 25 '12 at 12:49
  • Give me some time to try that out. Thank you for your effort. – Wolfgang Ziegler Jul 25 '12 at 12:52
0

You can override the GetChannelFactory and provide an implementation that can create a suitable endpoint i.e. a BasicHtppBinding with the proxy details added.

See here for a clue to how programmatically set Binding.

See here for starting point on creating the Channel Factory (see the 3 comments at the end of the post)

This shows how to use MetadataExchangeClient with a Custom Binding:

Here's the .NET Framework Source to MetadataExchangeClient so you can get a better understanding of what it is doing.

Community
  • 1
  • 1
Colin Smith
  • 11,811
  • 4
  • 34
  • 44