none
Specify Outgoing IP Address in Client WCF Configuration File RRS feed

  • Question

  • I am running a WCF service on a server. The client and servers connect and work well.

    The client PC has two IP addresses. One of them does not have access to the server due to permission issues. I would like to specify on the Client which IP address to use to connect to the server service. I am using Visual Studio 2013 and all the client setup is in the app.config file.

    Is there a way to do this?

    Thanks!


    Lebneen

    Wednesday, December 11, 2013 12:00 PM

Answers

  • Hi,

    A possible solution is using ServiceEndpoint.
    WCF give us the possibility to create a ServiceEndpoint for each IP/URL that we want to use (on the process level). In the moment when a request is made, the ServiceEndpoint will be used to resolve the client endpoint IP.
    At this level we can define a delegate that can be used to specify what IP needs to be used for each request. Because, when we create a ServiceEndpoint we specify the service endpoint address, we can have different server endpoints that will use different local IP.
    The BindIPEndPontDelegate delegate is called when the client IP needs to be resolved. When the local IP is specified in the callback we need to give a valid IP address of our machine, otherwise we will end up with an error. Don’t forget that this information can be cached by WCF. Also, we don’t specify a callback, the default behavior will be used.
    The code would look like this:

    ServicePoint servicePoint = 
          ServicePointManager.FindServicePoint(
                new Uri("https://www.myService.com/Services/Payment/"));
    servicePoint.BindIPEndPointDelegate =
                    (sp, rm, retryCount) =>
                    {
                                    return new IPEndPoint(myIpAddress, portNumber);
                    };
    
    

    In the callback, we can specify any IP to be used by using IPAddress.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, December 16, 2013 2:16 AM
    Moderator
  • Hi,

    >>Is there a way to include this in the configuration file?

    I am afraid that it will be some difficult to do this, but you can configure your client using code without a configure file.

    For more information, please try to refer to:
    #Hosting and consuming WCF services without configuration files :
    http://geekswithblogs.net/martinsj/archive/2012/10/14/hosting-and-consuming-wcf-services-without-configuration-files.aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, December 18, 2013 11:11 AM
    Moderator

All replies

  • Hi,

    A possible solution is using ServiceEndpoint.
    WCF give us the possibility to create a ServiceEndpoint for each IP/URL that we want to use (on the process level). In the moment when a request is made, the ServiceEndpoint will be used to resolve the client endpoint IP.
    At this level we can define a delegate that can be used to specify what IP needs to be used for each request. Because, when we create a ServiceEndpoint we specify the service endpoint address, we can have different server endpoints that will use different local IP.
    The BindIPEndPontDelegate delegate is called when the client IP needs to be resolved. When the local IP is specified in the callback we need to give a valid IP address of our machine, otherwise we will end up with an error. Don’t forget that this information can be cached by WCF. Also, we don’t specify a callback, the default behavior will be used.
    The code would look like this:

    ServicePoint servicePoint = 
          ServicePointManager.FindServicePoint(
                new Uri("https://www.myService.com/Services/Payment/"));
    servicePoint.BindIPEndPointDelegate =
                    (sp, rm, retryCount) =>
                    {
                                    return new IPEndPoint(myIpAddress, portNumber);
                    };
    
    

    In the callback, we can specify any IP to be used by using IPAddress.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, December 16, 2013 2:16 AM
    Moderator
  • Great. Is there a way to include this in the configuration file?

    Lebneen

    Monday, December 16, 2013 9:55 AM
  • Hi,

    >>Is there a way to include this in the configuration file?

    I am afraid that it will be some difficult to do this, but you can configure your client using code without a configure file.

    For more information, please try to refer to:
    #Hosting and consuming WCF services without configuration files :
    http://geekswithblogs.net/martinsj/archive/2012/10/14/hosting-and-consuming-wcf-services-without-configuration-files.aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, December 18, 2013 11:11 AM
    Moderator