0

I am hoping that someone could point me to a good 'simple' example, preferably using vb.net as opposed to c#, that demonstrates how one can dynamically configure the endpoint address at runtime in a windows forms application.

I have plenty of experience of creating dynamic connection strings for database connections but this is the first time that I have had to work with wcf and whilst what I have read seems to indicate that this is possible I have yet to find a good, simple working example that demonstrates the theory in practice.

The application that I am building needs to ship with a test address (linked to a test database) so that end users can establish that they are thoroughly conversant with what they need to do (they will be linking to an official government database in reality so successful trial runs are a pre-requisite) before using the real database in vain. As the only difference between the two is the address I would like to make this dynamically configurable.

I would welcome any suggestions or pointers that anyone could make on this subject.

Thanks

Dom Sinclair
  • 2,458
  • 1
  • 30
  • 47

1 Answers1

2

Pass service Uri to service proxy via constructor

            var serviceProxy = new YourClient(
                new BasicHttpBinding("BasicHttpBinding_IService"),
                new EndpointAddress(new Uri("http://server:port/address")));

YourClient class is auto generated, Visual Studio creates it when you are adding reference to the service. Binding name should be from your config file.


Edited: It looks your question was not or not only about client configuration, but also about service config. You can expose your service via more than one endpoint, you should add it to config file. And here was a question how to determine in code what exactly endpoind was accessed by the client. You can check this

OperationContext oc = OperationContext.Current;

if(oc != null)
{
    string wasCalledOn = oc.EndpointDispatcher.EndpointAddress.Uri.ToString();
}

and depending on wasCalledOn set database connection.

Community
  • 1
  • 1
paramosh
  • 2,258
  • 1
  • 15
  • 23