I have a question about MS webservices and web.config configuration.
I have a solution with two projects inside :
- Webservice ws_A a
- Website web_A
My website is connected to my website with “Web References” from Visual Studio. My webservice is connected to my database by :
public static SqlConnection sqlConn = new SqlConnection(myString);
In my webservice, I retrieve a connectionstring from webservice web.config with this method :
String sa = ConfigurationManager.ConnectionStrings["bdd"].ConnectionString;
I call the webservice via the website (WebReferences) and retrieve some informations from it.
But in order to retrieve the string in webservice, I need to declare this string in the website web.config. It is not logical because only the webservice need this string in order to save datas in database.
If I do not declare the string in the website web.config, I have a nullReferenceException in the webservice.
Anyone knows this problem and a solution in order to avoid to put the ConnectionString in the website ? It must don’t know the database existance !
EDIT :
To use my webservice, I do this in the website :
WebService1.WS_A webservice = new WebService1.WS_A();
If I’m understanding what you’re saying that’s not possible currently. The website is actually hosting the web service. So you are required to have all configuration in the web.config of the website.
If you don’t want the website to have the connection string to the database, at this point you need to create a separate project to HOST the web service. You can then configure the database connection inside that separate project and it will completely unknown to the first website.
At this point you will be truly using a webservice instead of creating a fancy service that’s self hosted and doesn’t buy you anything over a simple class.