By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,485 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,485 IT Pros & Developers. It's quick & easy.

Change WCF client endpoint address

P: n/a
Hi,

How could I change a WCF client endpoint address programatically? The client
is generated by Visual Studio. The purpose of doing this is to use different
service address under different configuration.

Thanks.

Daniel
Aug 22 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Aug 22, 3:50 am, Daniel <daniel.s...@newsgroup.nospamwrote:
Hi,

How could I change a WCF client endpoint address programatically? The client
is generated by Visual Studio. The purpose of doing this is to use different
service address under different configuration.

Thanks.

Daniel
Once you have an instance of the client side proxy 'ws', you can
change the URL via code like...

ws.Endpoint.Address = new
System.ServiceModel.EndpointAddress( newurl )

As a side notes, in my case I also have dynamic option to use HTTP or
HTTPS where I also have to specify which binding to use, so I have the
following code..

ws.Endpoint.Binding = new System.ServiceModel.BasicHttpBinding
( bHttps ? "httpsBinding" : "httpBinding" )

where the two values refer to binding names in the web.config file

Ron

Aug 22 '07 #2

P: n/a
Thanks Ron. I have tried this approach but it seems to have no effect. The
address still remains the same. Is there anything else I need to do to make
this work?

Daniel
"ro*************@yahoo.com" wrote:
On Aug 22, 3:50 am, Daniel <daniel.s...@newsgroup.nospamwrote:
Hi,

How could I change a WCF client endpoint address programatically? The client
is generated by Visual Studio. The purpose of doing this is to use different
service address under different configuration.

Thanks.

Daniel

Once you have an instance of the client side proxy 'ws', you can
change the URL via code like...

ws.Endpoint.Address = new
System.ServiceModel.EndpointAddress( newurl )

As a side notes, in my case I also have dynamic option to use HTTP or
HTTPS where I also have to specify which binding to use, so I have the
following code..

ws.Endpoint.Binding = new System.ServiceModel.BasicHttpBinding
( bHttps ? "httpsBinding" : "httpBinding" )

where the two values refer to binding names in the web.config file

Ron

Aug 23 '07 #3

P: n/a
Hi Daniel,

If what you want to do is just change the client WCF proxy's endpoint
address(in case you need to redirect to new server programmtically?), you
can use the following options:
1. You can pass a new Endpoint address instance(with the new url) in your
WCF client proxy's constructor, e.g.

<<<<<<<<<<<<<<<<<<<<
static void RunProxy()
{
HelloWorld.HelloWorldClient hello =
new
HelloWorld.HelloWorldClient("BasicHttpBinding_IHel loWorld",
new
EndpointAddress("http://localhost:8888/BasicHost/HelloWorld"));

string ret = hello.SayHello("WCF");

Console.WriteLine(ret);
}
>>>>>>>>>>>>>>>>

2. Or you can also create the WCF proxy first and change the
endpointAddress member after that. e.g.
>>>>>>>>>>>>>>>>
HelloWorld.HelloWorldClient client = new
WCFHelloWorldClient.HelloWorld.HelloWorldClient();

//change the endpointAddress here
client.Endpoint.Address = new
EndpointAddress("http://localhost:8899/BasicHost/HelloWorld");

Console.WriteLine(client.SayHello("steven"));

<<<<<<<<<<<<<<

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 23 '07 #4

P: n/a
Thanks Steven, the first approach works.

Daniel
"Steven Cheng[MSFT]" wrote:
Hi Daniel,

If what you want to do is just change the client WCF proxy's endpoint
address(in case you need to redirect to new server programmtically?), you
can use the following options:
1. You can pass a new Endpoint address instance(with the new url) in your
WCF client proxy's constructor, e.g.

<<<<<<<<<<<<<<<<<<<<
static void RunProxy()
{
HelloWorld.HelloWorldClient hello =
new
HelloWorld.HelloWorldClient("BasicHttpBinding_IHel loWorld",
new
EndpointAddress("http://localhost:8888/BasicHost/HelloWorld"));

string ret = hello.SayHello("WCF");

Console.WriteLine(ret);
}
>>>>>>>>>>>>>>>


2. Or you can also create the WCF proxy first and change the
endpointAddress member after that. e.g.
>>>>>>>>>>>>>>>

HelloWorld.HelloWorldClient client = new
WCFHelloWorldClient.HelloWorld.HelloWorldClient();

//change the endpointAddress here
client.Endpoint.Address = new
EndpointAddress("http://localhost:8899/BasicHost/HelloWorld");

Console.WriteLine(client.SayHello("steven"));

<<<<<<<<<<<<<<

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights
Aug 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.