473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y change web service information in app.config

Hi

How do I programmaticall y 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.service Model>
<bindings>
<basicHttpBindi ng>
<binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
openTimeout="00 :01:00"
receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
allowCookies="f alse"
bypassProxyOnLo cal="false"
hostNameCompari sonMode="Strong Wildcard"
maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
maxReceivedMess ageSize="671088 64"
messageEncoding ="Text" textEncoding="u tf-8"
transferMode="B uffered"
useDefaultWebPr oxy="true">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLength= "16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
<security mode="None">
<transport clientCredentia lType="None"
proxyCredential Type="None"
realm="" />
<message clientCredentia lType="UserName "
algorithmSuite= "Default" />
</security>
</binding>
</basicHttpBindin g>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicH ttpBinding" bindingConfigur ation="DataServ iceSoap"
contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
</client>
</system.serviceM odel>

Many thanks
Andrew
Aug 13 '08 #1
6 15307
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**@newsgroup s.nospamwrote in message
news:OD******** ******@TK2MSFTN GP03.phx.gbl...
Hi

How do I programmaticall y 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.service Model>
<bindings>
<basicHttpBindi ng>
<binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
openTimeout="00 :01:00"
receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
allowCookies="f alse"
bypassProxyOnLo cal="false"
hostNameCompari sonMode="Strong Wildcard"
maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
maxReceivedMess ageSize="671088 64"
messageEncoding ="Text" textEncoding="u tf-8"
transferMode="B uffered"
useDefaultWebPr oxy="true">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLength= "16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
<security mode="None">
<transport clientCredentia lType="None"
proxyCredential Type="None"
realm="" />
<message clientCredentia lType="UserName "
algorithmSuite= "Default" />
</security>
</binding>
</basicHttpBindin g>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicH ttpBinding" bindingConfigur ation="DataServ iceSoap"
contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
</client>
</system.serviceM odel>

Many thanks
Andrew
Aug 13 '08 #2
"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
message news:FB******** *************** ***********@mic rosoft.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**@newsgroup s.nospamwrote in message
news:OD******** ******@TK2MSFTN GP03.phx.gbl...
>Hi

How do I programmaticall y 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.service Model>
<bindings>
<basicHttpBindi ng>
<binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
openTimeout="0 0:01:00"
receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
allowCookies=" false"
bypassProxyOnLo cal="false"
hostNameCompar isonMode="Stron gWildcard"
maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
maxReceivedMes sageSize="67108 864"
messageEncoding ="Text" textEncoding="u tf-8"
transferMode=" Buffered"
useDefaultWebPr oxy="true">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLength ="16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
<security mode="None">
<transport clientCredentia lType="None"
proxyCredentia lType="None"
realm="" />
<message clientCredentia lType="UserName "
algorithmSuite ="Default" />
</security>
</binding>
</basicHttpBindin g>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicH ttpBinding"
bindingConfigu ration="DataSer viceSoap"
contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
</client>
</system.serviceM odel>

Many thanks
Andrew
No, that is not a good solution. How do you programmaticall y 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******** *************** ***********@mic rosoft.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**@newsgroup s.nospamwrote in message
news:OD******** ******@TK2MSFTN GP03.phx.gbl...
>Hi

How do I programmaticall y 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.service Model>
<bindings>
<basicHttpBindi ng>
<binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
openTimeout="0 0:01:00"
receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
allowCookies=" false"
bypassProxyOnLo cal="false"
hostNameCompar isonMode="Stron gWildcard"
maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
maxReceivedMes sageSize="67108 864"
messageEncoding ="Text" textEncoding="u tf-8"
transferMode=" Buffered"
useDefaultWebPr oxy="true">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLength ="16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
<security mode="None">
<transport clientCredentia lType="None"
proxyCredentia lType="None"
realm="" />
<message clientCredentia lType="UserName "
algorithmSuite ="Default" />
</security>
</binding>
</basicHttpBindin g>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicH ttpBinding"
bindingConfigu ration="DataSer viceSoap"
contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
</client>
</system.serviceM odel>

Many thanks
Andrew

Aug 14 '08 #4

"Andrew Jocelyn" <j0**@newsgroup s.nospamwrote in message
news:uD******** ******@TK2MSFTN GP06.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******** *************** ***********@mic rosoft.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**@newsgroup s.nospamwrote in message
news:OD******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Hi

How do I programmaticall y 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.service Model>
<bindings>
<basicHttpBindi ng>
<binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
openTimeout=" 00:01:00"
receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
allowCookies= "false"
bypassProxyOnLo cal="false"
hostNameCompa risonMode="Stro ngWildcard"
maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
maxReceivedMe ssageSize="6710 8864"
messageEncoding ="Text" textEncoding="u tf-8"
transferMode= "Buffered"
useDefaultWebPr oxy="true">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLengt h="16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
<security mode="None">
<transport clientCredentia lType="None"
proxyCredenti alType="None"
realm="" />
<message clientCredentia lType="UserName "
algorithmSuit e="Default" />
</security>
</binding>
</basicHttpBindin g>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicH ttpBinding"
bindingConfig uration="DataSe rviceSoap"
contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
</client>
</system.serviceM odel>

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**@newsgroup s.nospamwrote in message
news:uD******** ******@TK2MSFTN GP06.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******** *************** ***********@mic rosoft.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**@newsgroup s.nospamwrote in message
news:OD******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Hi

How do I programmaticall y 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.service Model>
<bindings>
<basicHttpBindi ng>
<binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
openTimeout=" 00:01:00"
receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
allowCookies= "false"
bypassProxyOnLo cal="false"
hostNameCompa risonMode="Stro ngWildcard"
maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
maxReceivedMe ssageSize="6710 8864"
messageEncoding ="Text" textEncoding="u tf-8"
transferMode= "Buffered"
useDefaultWebPr oxy="true">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLengt h="16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
<security mode="None">
<transport clientCredentia lType="None"
proxyCredenti alType="None"
realm="" />
<message clientCredentia lType="UserName "
algorithmSuit e="Default" />
</security>
</binding>
</basicHttpBindin g>
</bindings>
<client>
<endpoint address="http://webservice.com/Service.asmx"
binding="basicH ttpBinding"
bindingConfig uration="DataSe rviceSoap"
contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
</client>
</system.serviceM odel>

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
2227
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 local LAN connecting to an DB2 Universal 8.2 server. If that server goes down for some reason, I'd like to remotely shut down the client applications (I can do that), then change the DB2 configuration on the clients to connect to the backup
2
1825
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. Thx. PawelR.
0
1280
by: Konstantin | last post by:
Is there a way to add httpHandler programmatically instead of web.config? Thanks, Konstantin.
1
7987
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. <asp:TemplateColumn HeaderText="Rate1"> <ItemTemplate> <asp:Label runat="server" Text='<%# fRate(DataBinder.Eval(Container, "DataItem.RateAgentID")) %>' ID="Label3" NAME="Label3"> </asp:Label>
1
1207
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
36082
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 catalog=TimeDb;integrated security=SSPI;persist security info=False;workstation id=BOOMER;packet size=4096" But I want to be able to change some values, (e.g. data
0
2720
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
1905
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 and windows xp thx!
0
1148
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 these trace files that changes daily, eg : InputTrace20061203, ....? One way I have in mind to do this is to change the web.config file programmatically, but this seems not very elegant to me.
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.