开发者

Consuming the same WCF service from different addresses

I have a single WCF service but, until runtime, I don't know the correct address of the service. It may be :

http://example1.com/MyService.svc
// or
http://example2.com/MyService.svc

The service is used by a class library (DAL). I have two options:

  1. Add a service reference to the service (Visula Studio 2010) and change the address at run-time. This way VS-2010 will create WSDL and other stuff for me (I'm not sure if this is even possible).
  2. Create the proxy on the fly and set the base service address. This needs more work and if I make any change to service, I need to generate WSDL myself. Maintenance of this code is not as easy as option one.

Which option to use? Also if option two is recommended by you, then should I my clien开发者_开发百科t wrapper class be singleton or I can create all the connection stuff on each call?


you can point to localhost or any other address in development then in production if the url changes you simply modify the web.config or the app.config where you have configured the WCF end point.


Option 1 - you get all the advantages and none of the pain. Just use something factory-oriented (i.e. Don't do new MyProxy(), but instead stick that code somewhere central like a static CreateMyProxy() method, or consider an IoC/DI container).

How to consume WCF web service through URL at run time?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜