Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Choosing which service to use based on an appsetting

Choosing which service to use based on an appsetting

Scheduled Pinned Locked Moved Visual Basic
questionwcfsysadmindebugging
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daveg55
    wrote on last edited by
    #1

    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

    C M 2 Replies Last reply
    0
    • D daveg55

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      D 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        D Offline
        D Offline
        daveg55
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • D daveg55

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          1 Reply Last reply
          0
          • D daveg55

            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

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • M Mycroft Holmes

              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

              D Offline
              D Offline
              daveg55
              wrote on last edited by
              #6

              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.

              M 1 Reply Last reply
              0
              • D daveg55

                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.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups