471,317 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 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 15028
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by David Knaack | last post: by
2 posts views Thread by PawelR | last post: by
1 post views Thread by thibaut | last post: by
reply views Thread by Marc65 | last post: by

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.