none
WCF connection string from external config file RRS feed

  • Question

  • How can I assign the connection string from external config file to WCF ? my connection is defined in the external.config file. In 2002 we used to do it in appsetting node <appsetting file = "external.config"/> but with WCF /VS 2010 it gives an error. Is there any alternative?

    NV

    Saturday, September 7, 2013 3:03 PM

Answers

  • <copied>

    It works in ASP.Net Legacy web service but not in WCF. I will see the reading XML file option but have to do the coding . I hate that they removed this functionality from 2010.

    <end>

    You have your answers to the problem and a solution. So please mark the thread "answered" if it has helped you in any way.

    • Marked as answer by nik0812 Monday, September 9, 2013 6:17 PM
    Monday, September 9, 2013 6:15 PM

All replies

  • You may have to treat the config file like a XML file or just a text file and go read the data.
    Sunday, September 8, 2013 8:17 PM
  • Can you give me an example how would you refer the external config file in web.config file.

    NV

    Sunday, September 8, 2013 10:28 PM
  • <copied>

    Can you give me an example how would you refer the external config file in web.config file

    <end>

    What I am saying to you is that an app.config or a Web.config it is just a text file.

    1) You can use a textreader in code, open the file up pointing to its path and read the file line by line until you find the line that has the data you want and extract the data and use it in code. If you have read data from a .ini file back in the VS6 days, that's how one got configuration information that  a COM program needed. The .ini file was just a text file.

    On there other hand.....

    2) An app.config,  Web.config or an external.config is a XML file with XML tags that contain data. And there is nothing stopping from using Linq-2-XML and pointing to the path where the configuration file is located and reading the data in an XML like manner. Tell Linq-2-XML to locate the <connectionstring> tag and read the data in code and extract the data.

    It's a VB example, but if you are using C#, you can do the same thing.

    <http://blogs.msdn.com/b/wriju/archive/2008/04/02/linq-to-xml-changing-connectionstring-in-app-config.aspx>

     

     

    Sunday, September 8, 2013 10:57 PM
  • Thanks for the answer. I need to do something in code to achieve this but before I used to do it in web.config file 

    <appSettings file="../../Config/IRIS.Settings/ExternalConfig.xml"> 

    Can we do something like this in 2010?


    NV

    Sunday, September 8, 2013 11:21 PM
  • <copied>

    Can we do something like this in 2010?

    <end>

    I played with the externalconfig file once in the Web.config of a legacy Web service (non WCF WCF Web service).

    <appSettings file="../../Config/IRIS.Settings/ExternalConfig.xml"> 

    You are telling me it doesn't work for a WCF Web.config. I don't know. I'll take your word for it.

    Your test would be to create a ASP.NET Legacy Web Service and see if it works in that Web.config,  and then you'll know that there is something different in doing the same thing under WCF.

    You have alternatives to go read the XML file.

    Sunday, September 8, 2013 11:41 PM
  • It works in ASP.Net Legacy web service but not in WCF. I will see the reading XML file option but have to do the coding . I hate that they removed this functionality from 2010.

    NV

    Monday, September 9, 2013 4:12 PM
  • <copied>

    It works in ASP.Net Legacy web service but not in WCF. I will see the reading XML file option but have to do the coding . I hate that they removed this functionality from 2010.

    <end>

    You have your answers to the problem and a solution. So please mark the thread "answered" if it has helped you in any way.

    • Marked as answer by nik0812 Monday, September 9, 2013 6:17 PM
    Monday, September 9, 2013 6:15 PM