<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Usingnamespace - Blog &#187; Web services</title>
	<atom:link href="http://www.usingnamespace.org/category/web-services/feed" rel="self" type="application/rss+xml" />
	<link>http://www.usingnamespace.org</link>
	<description>C#, XUL, Javascript, C++ ...</description>
	<lastBuildDate>Tue, 17 Jul 2012 14:53:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[C#] Dynamically set the address of a webservice</title>
		<link>http://www.usingnamespace.org/c-dynamically-set-the-address-of-a-webservice.html</link>
		<comments>http://www.usingnamespace.org/c-dynamically-set-the-address-of-a-webservice.html#comments</comments>
		<pubDate>Sun, 07 Feb 2010 21:56:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web services]]></category>

		<guid isPermaLink="false">http://www.usingnamespace.org/?p=18</guid>
		<description><![CDATA[.NET is quite great to create and publish your own web services, and an eventually a client for it, almost without typing anything.
How to give your client the capacity to choose which server to connect to, in case of a distributed web service ?
When you create your web service in Visual studio, it asks you [...]]]></description>
			<content:encoded><![CDATA[<p>.NET is quite great to create and publish your own web services, and an eventually a client for it, almost without typing anything.<br />
How to give your client the capacity to choose which server to connect to, in case of a distributed web service ?</p>
<p>When you create your web service in Visual studio, it asks you for the address of the service in order to generate the Service Reference, and then writes this address into the config file.<br />
So, how to dynamically change the address of the targeted web service ?</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//We set the server's new address</span>
<span style="color: #FF0000;">string</span> server_address <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://www.newaddress.com:80&quot;</span><span style="color: #008000;">;</span>
ServiceName.<span style="color: #0000FF;">ServiceReferenceSoapClient</span> server <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ServiceName.<span style="color: #0000FF;">ServiceReferenceSoapClient</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">System</span>.<span style="color: #0000FF;">ServiceModel</span>.<span style="color: #0000FF;">EndpointAddress</span> addr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">ServiceModel</span>.<span style="color: #0000FF;">EndpointAddress</span><span style="color: #000000;">&#40;</span>server_address<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
server.<span style="color: #0000FF;">Endpoint</span>.<span style="color: #0000FF;">Address</span> <span style="color: #008000;">=</span> addr<span style="color: #008000;">;</span>
Uri site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Uri<span style="color: #000000;">&#40;</span>server_address<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
server.<span style="color: #0000FF;">Endpoint</span>.<span style="color: #0000FF;">ListenUri</span> <span style="color: #008000;">=</span> site<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//Then use the server as usual :</span>
server.<span style="color: #0000FF;">HelloWorld</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.usingnamespace.org/c-dynamically-set-the-address-of-a-webservice.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
