Choosing which service to use based on an appsetting
-
Hi all Noob question :) I'm using different web services depending on whether I want to connect to the development back end server or the production one. I'd like to choose which web service to use based on a setting in the web.config file. If I use a case statement (or if etc) to define my object the code complains that the object isn't declared. e.g. if Appsettings("Debug") = "True" then dim myObj as new devServer.Service else dim myObj as new prodServer.Service end if myVar = myObj.somethingClever name myobj is not declared Can this be done in some other way? Thanks Dave
-
Hi all Noob question :) I'm using different web services depending on whether I want to connect to the development back end server or the production one. I'd like to choose which web service to use based on a setting in the web.config file. If I use a case statement (or if etc) to define my object the code complains that the object isn't declared. e.g. if Appsettings("Debug") = "True" then dim myObj as new devServer.Service else dim myObj as new prodServer.Service end if myVar = myObj.somethingClever name myobj is not declared Can this be done in some other way? Thanks Dave
Your issue is that myObj exists within the scope of the if statements. Set myVar to be the right service within the code block, or define myObj outside it, so that it's visible outside of the scope of the if statement.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Your issue is that myObj exists within the scope of the if statements. Set myVar to be the right service within the code block, or define myObj outside it, so that it's visible outside of the scope of the if statement.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi Sure, I understand why the example doesn't work. For this trivial example it would be easy enough to define myVar within the code block. However, my question is whether there's another way of approaching this problem. Dave
It depends. I would probably put the two web services inside a single property that returns the right one based on the version, so I only do the check in one place. Beyond that, I don't see any better way to do it.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi all Noob question :) I'm using different web services depending on whether I want to connect to the development back end server or the production one. I'd like to choose which web service to use based on a setting in the web.config file. If I use a case statement (or if etc) to define my object the code complains that the object isn't declared. e.g. if Appsettings("Debug") = "True" then dim myObj as new devServer.Service else dim myObj as new prodServer.Service end if myVar = myObj.somethingClever name myobj is not declared Can this be done in some other way? Thanks Dave
We took a different route. When the user logs on they choose the server they want to work against. Typically they may have production, and 2-3 analysis servers they want to connect to. Additionally they can connect to UAT and dev servers by choice. So we pass in the server name from the UI. Caveat - all the servers must use the same credentials. We do have a different set of creds per application.
Never underestimate the power of human stupidity RAH
-
We took a different route. When the user logs on they choose the server they want to work against. Typically they may have production, and 2-3 analysis servers they want to connect to. Additionally they can connect to UAT and dev servers by choice. So we pass in the server name from the UI. Caveat - all the servers must use the same credentials. We do have a different set of creds per application.
Never underestimate the power of human stupidity RAH
-
Interesting. But how are you actually using the server name in the code? The problem I can't get my head around is how to do this without explicitly using the server when I define my objects.
Different development paradigm - all my objects are late bound. So during development the form objects are placed and named using a standard convention. A class is created to supply the CRUD and any other processing for each table. At runtime the class gets the table via the DAL and a utility binds the 1 row to the form elements or dumps the table into a datagridview.
Never underestimate the power of human stupidity RAH