Dynamically Switch Wcf Web Service Reference Url Path Through Config File

Dynamically switch WCF Web Service Reference URL path through config file

Are you just wanting to override the URL that is in the config to a different url. Say you have a test service and a live service. You can just do this.

client.Endpoint.Address = new EndpointAddress(Server.IsLiveServer() ?
@"LiveUrl" : @"TestURl");

Where those url come from wherever you want

Change service reference URL in code

Simply change the endpoint address, e.g.

clientProxy.Endpoint.Address = new EndpointAddress(yourUri);

How can I dynamically switch web service addresses in .NET without a recompile?

When you generate a web reference and click on the web reference in the Solution Explorer. In the properties pane you should see something like this:

Web Reference Properties

Changing the value to dynamic will put an entry in your app.config.

Here is the CodePlex article that has more information.

how to dynamic binding of web service URL

Are you using the <System.ServiceModel/> config section? If so you shouldn't have to do anything - the URL will be loaded from the <client/> section of the config when you create the channel.

A part of WCF service URL is generating dynamically each time

"(S(2wpucy0oasurckuompimgqdo))" is the session identity added to url. So to remove it from the url you should just disable the session store or move it to cookies. I.e. to disable session state you can add the following to your configuration file:

<system.web> 
<sessionState mode="Off" />
</system.web>

For more info please refer to the following articles on MSDN - ASP.NET Session State Overview, Session-State Modes

Dynamically changing config file for Web API does not find service endpoint

Good question!

Short answer:
You can't swap configurations, because web applications use a hierarchy of configuration files that is used in initialization when AppDomain starts, so this would require the restart of AppDomain, and all your in-memory changes would be lost (and this is how that "Config Swapper Class" assembly is intended to work - do everything in memory).

Details:
I did some digging and here is what I've found:

  1. It is not related to the way you load assembly with "Config Swapper Class" assembly, there is nothing there that could be affected by this.
  2. There is no point in restarting AppDomain if your actual configuration lives in memory - all changes would be lost. Probably you could think of another idea of where to store your configuration other than in web.config?
  3. The mentioned assembly (great stuff, BTW!) works in console application, because internally it uses ConfigurationManager, which itself uses ClientConfigurationSystem realization of IInternalConfigSystem interface. Web applications use WebConfigurationManager, that uses other realization of that interface - HttpConfigurationSystem.

    So, the "Config Swapper Class" assembly will not help you in web application because it operates on different set of internal classes.

Changing WCF Reference Url .Net Core

So as it seems this was the correct way to go about it but in the BasicHttpBinding constructor you have to explicitly say that it is BasicHttpSecurityMode.Transport and now it is working for me!



Related Topics



Leave a reply



Submit