开发者

How to check WCF generated client is compatible with service at runtime

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 m开发者_如何学Catches 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.


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....


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜