|
|
|
start date: Wed, 22 Aug 2007 01:50:06 -0700,
posted on: microsoft.public.dotnet.framework.webservices
back
| Thread Index |
|
1
Daniel am
|
|
2
unknown
|
|
3
Daniel am
|
|
4
(Steven Cheng[MSFT])
|
|
5
Daniel am
|
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
Date:Wed, 22 Aug 2007 01:50:06 -0700
Author:
|
Re: Change WCF client endpoint address
On Aug 22, 3:50 am, Daniel <daniel.s...@newsgroup.nospam> wrote:
> 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
Date:Wed, 22 Aug 2007 05:09:18 -0700
Author:
|
Re: Change WCF client endpoint address
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
"ronscottlangham@yahoo.com" wrote:
> On Aug 22, 3:50 am, Daniel <daniel.s...@newsgroup.nospam> wrote:
> > 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
>
>
Date:Wed, 22 Aug 2007 18:10:01 -0700
Author:
|
Re: Change WCF client endpoint address
{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang2052\f0\fs20 Hi Daniel,
\par
\par 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:
\par
\par
\par 1. You can pass a new Endpoint address instance(with the new url) in your WCF client proxy's constructor, e.g.
\par
\par <<<<<<<<<<<<<<<<<<<<
\par static void RunProxy()
\par \{
\par HelloWorld.HelloWorldClient hello =
\par new HelloWorld.HelloWorldClient("BasicHttpBinding_IHelloWorld",
\par new EndpointAddress("http://localhost:8888/BasicHost/HelloWorld"));
\par
\par string ret = hello.SayHello("WCF");
\par
\par Console.WriteLine(ret);
\par \}
\par >>>>>>>>>>>>>>>>
\par
\par
\par 2. Or you can also create the WCF proxy first and change the endpointAddress member after that. e.g.
\par
\par >>>>>>>>>>>>>>>>
\par
\par HelloWorld.HelloWorldClient client = new WCFHelloWorldClient.HelloWorld.HelloWorldClient();
\par
\par //change the endpointAddress here
\par client.Endpoint.Address = new EndpointAddress("http://localhost:8899/BasicHost/HelloWorld");
\par
\par Console.WriteLine(client.SayHello("steven"));
\par
\par <<<<<<<<<<<<<<
\par
\par Hope this helps.
\par
\par Sincerely,
\par
\par Steven Cheng
\par
\par Microsoft MSDN Online Support Lead
\par
\par
\par
\par ==================================================
\par
\par Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
\par
\par
\par
\par 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.
\par
\par ==================================================
\par \tab
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par
\par }
Date:Thu, 23 Aug 2007 03:06:52 GMT
Author:
|
Re: Change WCF client endpoint address
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_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
Date:Wed, 22 Aug 2007 20:30:01 -0700
Author:
|
|
|