0

Excuse my ignorance if this is something basic, I am somewhat new to the whole C# console application, using a Web Service Reference (WCF).

I am creating an application that will be places as an executable on many different machines and acts as a client to a web service. however, the web service is also installed in the client's local intranet, so the endpoint will change for each location.

I see the web reference endpoint is in the app.config file when adding within Visual Studio, but is there a simple way to change the endpoint at runtime, verify the endpoint is correct and exists, and be able to use the methods?

Also, if this is possible would I still need to add the SVC as a service reference in my Solution or would I call it dynamically?

I am using C# and .Net 4

Thanks

Tom Pennetta
  • 482
  • 7
  • 25

2 Answers2

1

You can put the address as an AppSetting and set it after creating your proxy class:

Proxy.Endpoint.Address = new EndpointAddress("myconfigvaluehere");
Jon
  • 3,230
  • 1
  • 16
  • 28
  • I am sorry, but what is the use of a separate proxy class? Do you need to create a class that inherits the SVC return object? – Tom Pennetta Jun 26 '12 at 18:46
  • Or is this created using the svcutil.exe? and just change the endpoint address in the code? – Tom Pennetta Jun 26 '12 at 18:48
  • Sorry, my code might have been misleading. You don't need a seperate proxy class, just set the EndPoint.Address on your service reference generated using svcutil.exe. – Jon Jun 26 '12 at 18:54
0

First - there's excellent book about WCF services by Juval Lowy: Programming WCF Services: Mastering WCF and the Azure AppFabric Service Bus. He explains along the book about WCF wrapper class that connect to WCF service dynamically using Endpoint, Binding and all that jazz. But you need to understand WCF background to continue working with it <- and you can do it from the book :)

Alex F
  • 3,180
  • 2
  • 28
  • 40