tags:

views:

22

answers:

3

I realise that WCF and services in general are meant to be loosely coupled.

But I have a requirement that my client app can check whether an given WCF endpoint contains a service that matches its generated client code. In other words I need to check for a compatible service.

Obviously I could have a method that returns a manually maintained version number, but I would prefer not to have to write my own meta data system if WCF can do something out of the box.

+2  A: 

If this works over HTTP and has service metadata and http get for service metadata enabled, you could retrieve the WSDL for the service from the

http://yourserver/yourservice/servicefile.svc?wsdl

address and then parse that WSDL and compare it to your client side proxy code. Pretty messy and long winded.

If that service metadata http get is disabled, however, you won't be able to retrieve the WSDL anymore :-( As long as service metadata is still enabled, you could check into the WCF classes and extract the metadata directly from the service endpoint - but that gets really really hairy.....

So back to your idea: why isn't a version number good enough?? That might really be the easiest way to go.... WCF doesn't really have anything "easy" like MyClient.CheckCompatibility(); or anything....

marc_s
Main problem with version number is remembering to increment it!
Schneider
@Schneider: that's probably the smaller problem that grabbing and parsing the WSDL! :-)
marc_s
+1  A: 

This will depend on how you define "compatible".

Maybe a simple version number would suffice? Maybe a more complicated major.minor.revision version number scheme would be necessary. In either case, the client would be told manually which service version it needs, and could call a GetVersion method on the service to see if that version is available.

John Saunders
A: 

I have thought of the other way to do this:

Share the service interface definition between client and server, then use the ChannelFactory to create the client at runtime.

http://msdn.microsoft.com/en-us/library/ms734681.aspx

Schneider