locked
Dynamically change the Database Connection string in WCF Service RRS feed

  • Question

  • Hi,

     

    I have created a WCF Service that exposing endpoint with WEBHTTP Bindings. Now i want to host this service at one server and want to consume this service in Multiple applications those are having diff-2 database.

    So instead of assigning Database Connection string in WebConfig, i want to assign DB Connection String dynamically on the basis of Calling Client Website.

     

    Could any one help me with the optimum solution in details.

     

    Thanks

    Parveen Punia

    Tuesday, August 10, 2010 11:04 AM

Answers

  • Hi,

     

    if I understand correctly, you question boils down to : "How can I determine the remote address of the client that is calling me?"

    If that is your question, see here for a possible solution.

     

    However, if some of the calling applications are on the same machine, this will not going to help you. In this case, you could add a custom header (e.g. "ClientApplicationName") to the messages and retrieve the value through OperationContext. IncomingMessageHeaders on the server side.

    On information how to add headers to an outgoing message without changing the compiled code click here .

     

    Regards,

    Markus

    • Marked as answer by Bin-ze Zhao Monday, August 16, 2010 1:22 PM
    • Unmarked as answer by Bin-ze Zhao Monday, August 16, 2010 1:22 PM
    • Marked as answer by Bin-ze Zhao Thursday, August 19, 2010 3:23 AM
    Tuesday, August 10, 2010 11:52 AM

All replies

  • Hi,

     

    if I understand correctly, you question boils down to : "How can I determine the remote address of the client that is calling me?"

    If that is your question, see here for a possible solution.

     

    However, if some of the calling applications are on the same machine, this will not going to help you. In this case, you could add a custom header (e.g. "ClientApplicationName") to the messages and retrieve the value through OperationContext. IncomingMessageHeaders on the server side.

    On information how to add headers to an outgoing message without changing the compiled code click here .

     

    Regards,

    Markus

    • Marked as answer by Bin-ze Zhao Monday, August 16, 2010 1:22 PM
    • Unmarked as answer by Bin-ze Zhao Monday, August 16, 2010 1:22 PM
    • Marked as answer by Bin-ze Zhao Thursday, August 19, 2010 3:23 AM
    Tuesday, August 10, 2010 11:52 AM
  • Hi,

    Not sure what you demand at this stage, do you mean let the service to assign database string for your client application?

    where the 2 database settled? on your server side or on your client application side

    Please detail your question, we can only help you based on this.

    Thanks

    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Thursday, August 19, 2010 3:23 AM
    • Unmarked as answer by Bin-ze Zhao Thursday, August 19, 2010 3:23 AM
    Monday, August 16, 2010 1:29 PM
  • I have a similar situation whereas a I have single WCF service hosted on a server that hosts a connection to a database.  This is WCF service is currently accessed by a WinForms application.  My customer would like to have the capability to be able to change the database being accessed when the WinForms application starts.  On the database server there would be multiple separate databases that have identical structures and programability.  Upon startup of the WinForms application,  which connects to the one WCF service,  the user would choose the database they wish to connect to. Not needing the capability of connecting to multiple databases simultaneously, just the ability to change which database to use at application startup.  What are the best methodes for implementing this type of scenario?

    Thanks

    LThibx

    Monday, December 27, 2010 4:31 PM