reading Web.config with ConfigurationSetting HELP??

J

james

I have a Winforms app and a WebService. When the win app calls
the service, the service reads the config file like so

ConfigurationSettings.AppSettings["myKey"]

but, the WebService is getting the app.config from the win app
NOT the Web.config settings.

Read:: Accessing ASP.NET Configuration Settings and it states to
use ConfigurationSettings.AppSettings, so why wont it read Web.config ?

thanks,

JIM
 
J

Jan Tielens

Are you sure you are accessing the webservice through SOAP? The webservice
indeed should read the web.config file! I'm pretty sure it does (normally)
because I've done this numerous times...

In fact I don't think it's possible due to a number of issues (security,
application boundaries, ...).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
J

james

Well, I follow the MS example on creating an WebService. Simply reference
the web service and call the properties in the object like so

value = MyWebService.MyObject.SomeStaticProperty()

now inside SomeStaticProperty() I do this

public class Util : System.Web.Services.WebService
{

....
[WebMethod(Description="Does something", EnableSession=false)]
public static string SomeStaticProperty()
{
return ConfigurationSettings.AppSettings["SomeValue"];
}


and the XML in Web.config

.....
<appSettings>
<add key="SomeValue" value="xxxxx" />
</appSettings>


thanks for the help



Jan Tielens said:
Are you sure you are accessing the webservice through SOAP? The webservice
indeed should read the web.config file! I'm pretty sure it does (normally)
because I've done this numerous times...

In fact I don't think it's possible due to a number of issues (security,
application boundaries, ...).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
I have a Winforms app and a WebService. When the win app calls
the service, the service reads the config file like so

ConfigurationSettings.AppSettings["myKey"]

but, the WebService is getting the app.config from the win app
NOT the Web.config settings.

Read:: Accessing ASP.NET Configuration Settings and it states to
use ConfigurationSettings.AppSettings, so why wont it read Web.config ?

thanks,

JIM
 
J

Jan Tielens

How do you call that static property?

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
Well, I follow the MS example on creating an WebService. Simply reference
the web service and call the properties in the object like so

value = MyWebService.MyObject.SomeStaticProperty()

now inside SomeStaticProperty() I do this

public class Util : System.Web.Services.WebService
{

...
[WebMethod(Description="Does something", EnableSession=false)]
public static string SomeStaticProperty()
{
return ConfigurationSettings.AppSettings["SomeValue"];
}


and the XML in Web.config

....
<appSettings>
<add key="SomeValue" value="xxxxx" />
</appSettings>


thanks for the help



Jan Tielens said:
Are you sure you are accessing the webservice through SOAP? The webservice
indeed should read the web.config file! I'm pretty sure it does (normally)
because I've done this numerous times...

In fact I don't think it's possible due to a number of issues (security,
application boundaries, ...).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
I have a Winforms app and a WebService. When the win app calls
the service, the service reads the config file like so

ConfigurationSettings.AppSettings["myKey"]

but, the WebService is getting the app.config from the win app
NOT the Web.config settings.

Read:: Accessing ASP.NET Configuration Settings and it states to
use ConfigurationSettings.AppSettings, so why wont it read Web.config ?

thanks,

JIM
 
J

james

Jan,

See below, the line that says this::

is this wrong ?

thanks,

JIM


Jan Tielens said:
How do you call that static property?

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
Well, I follow the MS example on creating an WebService. Simply reference
the web service and call the properties in the object like so

value = MyWebService.MyObject.SomeStaticProperty()

now inside SomeStaticProperty() I do this

public class Util : System.Web.Services.WebService
{

...
[WebMethod(Description="Does something", EnableSession=false)]
public static string SomeStaticProperty()
{
return ConfigurationSettings.AppSettings["SomeValue"];
}


and the XML in Web.config

....
<appSettings>
<add key="SomeValue" value="xxxxx" />
</appSettings>


thanks for the help



Jan Tielens said:
Are you sure you are accessing the webservice through SOAP? The webservice
indeed should read the web.config file! I'm pretty sure it does (normally)
because I've done this numerous times...

In fact I don't think it's possible due to a number of issues (security,
application boundaries, ...).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


I have a Winforms app and a WebService. When the win app calls
the service, the service reads the config file like so

ConfigurationSettings.AppSettings["myKey"]

but, the WebService is getting the app.config from the win app
NOT the Web.config settings.

Read:: Accessing ASP.NET Configuration Settings and it states to
use ConfigurationSettings.AppSettings, so why wont it read
Web.config
 
J

Jan Tielens

Aah, I see the problem! I think you are using your web service directly. You
should add a web reference to your web service (not a normal reference) and
then use the following code:

Dim s As New referenceName.MyObject
value = s.SomeStaticProperty

Also, I think the static keyword doesn't make any sense when using a web
service:
public static string SomeStaticProperty()
should be
public string SomeStaticProperty()
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
Jan,

See below, the line that says this::

is this wrong ?

thanks,

JIM


Jan Tielens said:
How do you call that static property?

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
Well, I follow the MS example on creating an WebService. Simply reference
the web service and call the properties in the object like so

value = MyWebService.MyObject.SomeStaticProperty()

now inside SomeStaticProperty() I do this

public class Util : System.Web.Services.WebService
{

...
[WebMethod(Description="Does something", EnableSession=false)]
public static string SomeStaticProperty()
{
return ConfigurationSettings.AppSettings["SomeValue"];
}


and the XML in Web.config

....
<appSettings>
<add key="SomeValue" value="xxxxx" />
</appSettings>


thanks for the help



Are you sure you are accessing the webservice through SOAP? The webservice
indeed should read the web.config file! I'm pretty sure it does (normally)
because I've done this numerous times...

In fact I don't think it's possible due to a number of issues (security,
application boundaries, ...).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


I have a Winforms app and a WebService. When the win app calls
the service, the service reads the config file like so

ConfigurationSettings.AppSettings["myKey"]

but, the WebService is getting the app.config from the win app
NOT the Web.config settings.

Read:: Accessing ASP.NET Configuration Settings and it states to
use ConfigurationSettings.AppSettings, so why wont it read
Web.config
?

thanks,

JIM
 
J

james

Jan,

I changed the methods to non static, and instantiated my webservice i.e.
C#
MyWebSevice.MyUtility utility = new MyWebSevice.MyUtility();

so now the calls look like this

string setting = utility.GetSomeAppSetting();

but guess what ? It still gets the app setting from the calling app
not the Web.config !

Sorry, any other ideas??

MVP ???


thanks for your help

JIM

Jan Tielens said:
Aah, I see the problem! I think you are using your web service directly. You
should add a web reference to your web service (not a normal reference) and
then use the following code:

Dim s As New referenceName.MyObject
value = s.SomeStaticProperty

Also, I think the static keyword doesn't make any sense when using a web
service:
public static string SomeStaticProperty()
should be
public string SomeStaticProperty()
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


james said:
Jan,

See below, the line that says this::
value = MyWebService.MyObject.SomeStaticProperty()


is this wrong ?

thanks,

JIM


Jan Tielens said:
How do you call that static property?

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


Well, I follow the MS example on creating an WebService. Simply
reference
the web service and call the properties in the object like so

value = MyWebService.MyObject.SomeStaticProperty()

now inside SomeStaticProperty() I do this

public class Util : System.Web.Services.WebService
{

...
[WebMethod(Description="Does something", EnableSession=false)]
public static string SomeStaticProperty()
{
return ConfigurationSettings.AppSettings["SomeValue"];
}


and the XML in Web.config

....
<appSettings>
<add key="SomeValue" value="xxxxx" />
</appSettings>


thanks for the help



Are you sure you are accessing the webservice through SOAP? The
webservice
indeed should read the web.config file! I'm pretty sure it does
(normally)
because I've done this numerous times...

In fact I don't think it's possible due to a number of issues (security,
application boundaries, ...).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


I have a Winforms app and a WebService. When the win app calls
the service, the service reads the config file like so

ConfigurationSettings.AppSettings["myKey"]

but, the WebService is getting the app.config from the win app
NOT the Web.config settings.

Read:: Accessing ASP.NET Configuration Settings and it states to
use ConfigurationSettings.AppSettings, so why wont it read Web.config
?

thanks,

JIM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top