Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2007

Tip: Looking for answers? Try searching our database.

Change WCF client endpoint address

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel - 22 Aug 2007 09:50 GMT
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
ronscottlangham@yahoo.com - 22 Aug 2007 13:09 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> 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
Daniel - 23 Aug 2007 02:10 GMT
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

> > Hi,
> >
[quoted text clipped - 22 lines]
>
> Ron
Steven Cheng[MSFT] - 23 Aug 2007 04:06 GMT
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_IHelloWorld",
                   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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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

This posting is provided "AS IS" with no warranties, and confers no rights.
Daniel - 23 Aug 2007 04:30 GMT
Thanks Steven, the first approach works.

Daniel

> Hi Daniel,
>
[quoted text clipped - 67 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.