473,326 Members | 2,061 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,326 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 56848
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.