473,406 Members | 2,273 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,406 software developers and data experts.

Change WCF client endpoint address

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
4 56872
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gleb | last post by:
Is it possible to know client IP address in Web Service method using Apache SOAP on Tomcat? Thank you.
8
by: Homer | last post by:
How can I obtain the client IP address or machine name from within an asp.net application? I want to use this information to determine where to redirect a web page. Many thanks Homer
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
0
by: tracy | last post by:
CHANGE OF EMAIL ADDRESS NOTIFICATION Dear Clients, Suppliers & Friends, Effective August 1st 2005, my new email address will be tracytaw@swotdesigngroup.com. During this transition period,...
19
by: chee.k.cheng | last post by:
Hi, I'm wondering if it is possible to change the starting address of a structure element. For example, I have the following structure: struct demo { char digit; char alpha; } an;
13
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
1
by: Tony | last post by:
I would really appreciate it if anyone has any thoughts on this one - it's driving us mad. We have a web site which is using ASP.NET 1.1 and which is load balanced across two web servers with IP...
0
by: Jeremy Monnet | last post by:
Hello, I've started python a few weeks ago, and to now everything went fine with my cookbook and a learning book. Now, I've tried the SimpleXMLRPCServer, and it worked OK untill I tried to...
10
by: skyy | last post by:
Hi.. I am working on a CGI script to enable client to obtain the server ip address and then change to the IP address it prefer. The server IP address can be obtain from the environment variable...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.