Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
In my asp .net website config file,i configured the servcie.

The same servcie configured on various servers.
In my website i have various tabs that is for various servers. So while clicking on that tab,website automatically select particular service endpoint and perform the operation.

So anybody have idea on this ,how may i achive this?

XML
<client>
     <endpoint address=""
         binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
         contract="IService" name="BasicHttpBinding_IService" />
   </client>
Posted
Updated 9-Oct-13 20:15pm
v2
Comments
Kishor Deshpande 10-Oct-13 2:35am    
You have to programmatically configure the binding in your code.
1) Store 2 key values in config
2) In code fetch values to the key/ address you want to configure the service to and expose the service

Yes you can.Check below details for more info.

Quote:
I think what you want is to swap out at runtime a version of your config file, if so create a copy of your config file (also give it the relevant extension like .Debug or .Release) that has the correct addresses (which gives you a debug version and a runtime version ) and create a postbuild step that copies the correct file depending on the build type.

Here is an example of a postbuild event that I've used in the past which overrides the output file with the correct version (debug/runtime)


copy "$(ProjectDir)ServiceReferences.ClientConfig.$(ConfigurationName)" "$(ProjectDir)ServiceReferences.ClientConfig" /Y


where : $(ProjectDir) is the project directory where the config files are located $(ConfigurationName) is the active configuration build type

For more info : How to programmatically modify WCF app.config endpoint address setting

Another Link : Programmatically Configure a WCF Endpoint

I hope this will help to you.
 
Share this answer
 
v2
You may have several configuration files for the services, and generate your communication channels from them, e.g.
C#
public static ServerSide.IMyFirstService GetMyFirstService()
{
    string configFile = Clients.DetermineConfigFile("MyFirstService"); // a function to determine the correct config file
    Configuration myFirstServiceConfiguration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configFile }, ConfigurationUserLevel.None);
    ConfigurationChannelFactory<IMyFirstService> myFirstServiceChannelFactory = new ConfigurationChannelFactory<IMyFirstService>("TCPEndpoint", myFirstServiceConfiguration, null);
    IMyFirstService myFirstServiceClient = myFirstServiceChannelFactory.CreateChannel();
    return myFirstServiceClient;
}

When you change the tab, change the service used accordingly.
 
Share this answer
 
Here is another solution. Not sure if it will help you.

Access WCF Service without config[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900