Dynamic IP

I write Client and Server in Wcf and i have problem with base address.

The Server take the base address from other source ( dll config i write )

Uri baseAddress = TakeBaseIP();

// Create a ServiceHost for the CalculatorService type and provide the base address.

using (ServiceHost serviceHost = new ServiceHost(typeof(GeneralService), baseAddress))

// Open the ServiceHostBase to create listeners and start listening for messages.

serviceHost.Open();

when i use in svcutil the file contain the ip of server(base address).

<client>

<endpoint name=""

address=http://localhost:8000/GeneralService

binding="wsHttpBinding"

bindingConfiguration="Binding1"

contract="IDataContractGeneralService" />

</client>

i want to write client that does not depend in base address of output.config.

how i can write client side generic so that i does not depend if base address

in server side is changed .

i




Answer this question

Dynamic IP

  • jack katz

    As I wrote in my previous message, according to the WCF code (thanks to reflector), the address you specifically created in your code will be used, overriding the one in the config file.

    You can also use proxy.Endpoint.Binding or proxy.Endpoint.Address to change those values after it's created.


  • jumanjiCA

    10x

  • Mike Cating

    I have code  like this .

    EndpointAddress EndPointAdressObj= new EndpointAddress("http://localhost:8000/servicemodelsamples/service/pop");

    CalculatorProxy proxy = new CalculatorProxy("EndPoint1",EndPointAdressObj)

    and in App.config file

    <client>

    <endpoint name="EndPoint1"

    address=http://localhost:8000/servicemodelsamples/service/General

    binding="wsHttpBinding"

    bindingConfiguration="Binding1"

    contract="ICalculator">

    </endpoint>

    </client>

     The client accept Address from 2 sources from App.config

    in From code

    Which Address the client connect to App.config or  code.

    10x

     

     



  • al kerr

    I want all the data in "EndPoint1" (Binding etc)

    except  address .

    The address i accept from user and i can't to take from "EndPoint"

    in other words  i want all data except address in "EndPoint" except address .

    how i can to change the data after i  call to constructor

    CalculatorProxy("EndPoint1") with address that i don't  want .  

     

    the constructor acccept

    CalculatorProxy(string endpointConfigurationName, string remoteAddress)

    if i type in second parameter the right address

    which address the client connect the first or the second.

    Why have duplicate if endpointconfigurationname contain the

    address.    

     

       



  • SpiderX81

    Adiavn wrote:
    As I wrote in my previous message, according to the WCF code (thanks to reflector), the address you specifically created in your code will be used, overriding the one in the config file.

    It's best not to rely on observed behavior, even if you confirmed it via Reflector. Especially for beta software. If it's not documented to override the configured address, don't assume that this behavior will not change in the future, even in the next beta.

    Adiavn wrote:
    You can also use proxy.Endpoint.Binding or proxy.Endpoint.Address to change those values after it's created.

    This is a much better solution. Not only because you're more future-proof, but also because your code is clearer and more explicit.


  • Beniton

    Hi

    First of all, the base address and the endpoint address are two different things - the base address is the address in which the service exposes it's WSDL metadata information. The client connects to the endpoint on another address.

    The simple option is to create the address (Uri) object in your code, and not from configuration file (you'll still need to get it from somewhere):

    http://windowssdk.msdn.microsoft.com/library/default.asp url=/library/en-us/cpref19/html/T_System_ServiceModel_ChannelFactory`1.asp

    Another thing you may do is use a fixed base address for the client to connect to and retrieve a dynamic endpoint address:

    http://www.idesign.net/idesign/DesktopDefault.aspx tabindex=-1&tabid=19&download=158

    And here is another solution:

    http://pluralsight.com/blogs/mvernal/archive/2006/03/06/19814.aspx


  • mr.flx

    According to the ChannelFactory.InitializeEndpoint method, which is the one called by the proxy, the address used will be the one you created in your code.

    Any special reason to write such code it seems more logical to simply use

    new CalculatorProxy("EndPoint1")


  • Dynamic IP