wcfcontractwcf-discovery

Getting the contract


Is there a way to get a contract from a running service programatically? I want to compare the contract of a running service from a referenced contract in the client side.

For example I have two instances of Service1 running on different machines that has different implementations. They both have a contract named IService1 but different implementation. I have a Console1 that has a reference to IService1(First instance). Console1 has a collection of 2 endpoint address. Console1 wants to check which of the running services is the correct service for the contract(First instance) he is using.

What I want to do here is to programatically get the contract from the service using the address and compare it to the referenced contract that I have.


Solution

  • If the service exposes metadata it is possible yes. Exactly how depends on the binding used, if it is a normal http binding you can use http://myserver/myservice.svc?WSDL. To compare the contracts you would have to download the WSDL by using a normal http API and then compare it to a stored reference WSDL.

    There are also a few things I think you should take into consideration before implementing a comparison: