473,219 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

Programmatically change web service information in app.config

Hi

How do I programmatically change (read/write) the values in this app.config
file at runtime? Specifically I want to change the client endpoint address
but it would be nice to change other values too. I thought this is what
ServiceHost is for but is seems way more complicated to use for what I'm
trying to do.

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="67108864" maxBufferPoolSize="524288"
maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="DataServiceSoap"
contract="MyService.DataServiceSoap" name="DataServiceSoap" />
</client>
</system.serviceModel>

Many thanks
Andrew
Aug 13 '08 #1
6 15252
It's a file, you can read and write it as normal. However, you will restart
the application. Now, step back a bit. Endpoints are established ahead of
time and configured accordingly. Your requirement is about the same as
rewriting a browser url so that clients can hit this new url. Why not
publish the url ahead of time? Why the strange requirement?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
Hi

How do I programmatically change (read/write) the values in this
app.config file at runtime? Specifically I want to change the client
endpoint address but it would be nice to change other values too. I
thought this is what ServiceHost is for but is seems way more complicated
to use for what I'm trying to do.

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="67108864" maxBufferPoolSize="524288"
maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="DataServiceSoap"
contract="MyService.DataServiceSoap" name="DataServiceSoap" />
</client>
</system.serviceModel>

Many thanks
Andrew
Aug 13 '08 #2
"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
message news:FB**********************************@microsof t.com...
It's a file, you can read and write it as normal. However, you will
restart the application. Now, step back a bit. Endpoints are established
ahead of time and configured accordingly. Your requirement is about the
same as rewriting a browser url so that clients can hit this new url. Why
not publish the url ahead of time? Why the strange requirement?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
>Hi

How do I programmatically change (read/write) the values in this
app.config file at runtime? Specifically I want to change the client
endpoint address but it would be nice to change other values too. I
thought this is what ServiceHost is for but is seems way more complicated
to use for what I'm trying to do.

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="67108864" maxBufferPoolSize="524288"
maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicHttpBinding"
bindingConfiguration="DataServiceSoap"
contract="MyService.DataServiceSoap" name="DataServiceSoap" />
</client>
</system.serviceModel>

Many thanks
Andrew
No, that is not a good solution. How do you programmatically change the
endpoints? We have the same requirement. I suspect we can just define two
endpoints (binding names) in the config as you suggest however, then choose
which one to use at runtime. We have an application that needs to easily
switch between sandbox and production environment web services.

Jeff
Aug 14 '08 #3
OK, this is the situation.

The windows form client is a ClickOnce app and will be downloaded from a
central location. It needs some default config but the webservice it will
need to connect to will be customer specific, i.e. each client will need to
connect to their own URL.

Perhaps this is poor design but it's more secure than allowing all clients
to connect to a single service. I know I can deserialize/serialize the
app.config but there must be a preferred way to modify these particular
settings. I don't want the user to modify the file directly.

Also it seems like there may be occasions when things like maxBufferSize
need to be tweaked so an interface of seems like it should be a common
requirement to me. What do other people do?

Thanks
Andrew

"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
message news:FB**********************************@microsof t.com...
It's a file, you can read and write it as normal. However, you will
restart the application. Now, step back a bit. Endpoints are established
ahead of time and configured accordingly. Your requirement is about the
same as rewriting a browser url so that clients can hit this new url. Why
not publish the url ahead of time? Why the strange requirement?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
>Hi

How do I programmatically change (read/write) the values in this
app.config file at runtime? Specifically I want to change the client
endpoint address but it would be nice to change other values too. I
thought this is what ServiceHost is for but is seems way more complicated
to use for what I'm trying to do.

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="67108864" maxBufferPoolSize="524288"
maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicHttpBinding"
bindingConfiguration="DataServiceSoap"
contract="MyService.DataServiceSoap" name="DataServiceSoap" />
</client>
</system.serviceModel>

Many thanks
Andrew

Aug 14 '08 #4

"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:uD**************@TK2MSFTNGP06.phx.gbl...
OK, this is the situation.

The windows form client is a ClickOnce app and will be downloaded from a
central location. It needs some default config but the webservice it will
need to connect to will be customer specific, i.e. each client will need
to connect to their own URL.

Perhaps this is poor design but it's more secure than allowing all clients
to connect to a single service. I know I can deserialize/serialize the
app.config but there must be a preferred way to modify these particular
settings. I don't want the user to modify the file directly.

Also it seems like there may be occasions when things like maxBufferSize
need to be tweaked so an interface of seems like it should be a common
requirement to me. What do other people do?

Thanks
Andrew

"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote
in message news:FB**********************************@microsof t.com...
>It's a file, you can read and write it as normal. However, you will
restart the application. Now, step back a bit. Endpoints are established
ahead of time and configured accordingly. Your requirement is about the
same as rewriting a browser url so that clients can hit this new url. Why
not publish the url ahead of time? Why the strange requirement?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
>>Hi

How do I programmatically change (read/write) the values in this
app.config file at runtime? Specifically I want to change the client
endpoint address but it would be nice to change other values too. I
thought this is what ServiceHost is for but is seems way more
complicated to use for what I'm trying to do.

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="67108864" maxBufferPoolSize="524288"
maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicHttpBinding"
bindingConfiguration="DataServiceSoap"
contract="MyService.DataServiceSoap" name="DataServiceSoap" />
</client>
</system.serviceModel>

Many thanks
Andrew

Keep in mind that the web service proxy/client constructor is overloaded and
can take the endpoint address as a parameter
Aug 14 '08 #5
OK, this is the situation.
Yes I suspected that was half the story but I wanted to be polite about it.

The recommended solution is to define multiple endpoints. Bear in mind, WCF
is designed to be coded once and configured appropriately in production.
Things like adding endpoints should not be addressed at the code level, they
should rightly be handled by support professional 'in production' with no
touch to the code.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:uD**************@TK2MSFTNGP06.phx.gbl...
OK, this is the situation.

The windows form client is a ClickOnce app and will be downloaded from a
central location. It needs some default config but the webservice it will
need to connect to will be customer specific, i.e. each client will need
to connect to their own URL.

Perhaps this is poor design but it's more secure than allowing all clients
to connect to a single service. I know I can deserialize/serialize the
app.config but there must be a preferred way to modify these particular
settings. I don't want the user to modify the file directly.

Also it seems like there may be occasions when things like maxBufferSize
need to be tweaked so an interface of seems like it should be a common
requirement to me. What do other people do?

Thanks
Andrew

"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote
in message news:FB**********************************@microsof t.com...
>It's a file, you can read and write it as normal. However, you will
restart the application. Now, step back a bit. Endpoints are established
ahead of time and configured accordingly. Your requirement is about the
same as rewriting a browser url so that clients can hit this new url. Why
not publish the url ahead of time? Why the strange requirement?

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Andrew Jocelyn" <j0**@newsgroups.nospamwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
>>Hi

How do I programmatically change (read/write) the values in this
app.config file at runtime? Specifically I want to change the client
endpoint address but it would be nice to change other values too. I
thought this is what ServiceHost is for but is seems way more
complicated to use for what I'm trying to do.

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="67108864" maxBufferPoolSize="524288"
maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicHttpBinding"
bindingConfiguration="DataServiceSoap"
contract="MyService.DataServiceSoap" name="DataServiceSoap" />
</client>
</system.serviceModel>

Many thanks
Andrew

Aug 14 '08 #6

Thanks Jeff
>
Keep in mind that the web service proxy/client constructor is overloaded
and can take the endpoint address as a parameter
That's the answer I was looking for. For now anyway.

Andrew
Aug 15 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Knaack | last post by:
Howdy I'm new to working with DB2 Universal, so I'm not very familiar with the tools. I usually only use the Java Control Center and Configuration Assistant. I have several clients on the...
2
by: PawelR | last post by:
Hello group, In my applicationa I use web.config parameter for sqlConnectionString etc. How change parameter in web.config via website - one of site in my application - as opiton/seting site. ...
0
by: Konstantin | last post by:
Is there a way to add httpHandler programmatically instead of web.config? Thanks, Konstantin.
1
by: Craig | last post by:
How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change the databinding to another column at runtime. ...
1
by: thibaut | last post by:
Hi, Is it possible to programmatically change iis rights on a file or a directory (allow write access on xml files, deny download for databases,...). Thanks for your help
4
by: jasiglam | last post by:
Using the visual studio.net text editor, I know how to enter/change the "key/value" in the app.config file, for example: key="SqlConnection1.ConnectionString" value="data source=Boomer;initial...
0
by: jj | last post by:
How do you programmatically change a "windows Service account" from Local system to Network or Local service by providing username and password? Thanks
1
by: scott | last post by:
I create a service project and build into service.exe , intall it as system service. With a service.exe.config file in the directory as service.exe. so that I can not start service. I use vs2005...
0
by: Marc65 | last post by:
Hello, I wrote a webservice using WSE2. I enabled the tracing, to write in InputTrace.log and OutputTrace.log. These files remain locked, and grow fast. Is there a way to have a name for...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.