Since I have answered this question a few times now I decided to write a post about it. maybe it helps some others who have the same question: “What is the difference between MEX and WSDL as a meta-data description for WCF service” and probably the next question: “When we should prefer one to the other?”
MEX and WSDL are both ways of publishing meta-data information from your services. WSDL is more known since it’s been around for more time than MEX. It is currently in use with a lot of web services in real world. Since they both are automatically generated for your service based on the same meta-data there is no important regarding the completeness and consistency. In short: They are the same! The only differences are as follows:
- WSDL exposes this information as a WSDL document which is accessible by an HTTP GET request (and you can easily check it in a browser) but MEX exposes the same information as a SOAP message over http, tcp and named pipes
- MEX generates one message containing all the meta-data but WSDL generate one that contains a description of Operations and one for each data contract and the URL for those are also included in the root document. In other words, MEX generates a big message containing all the required information which requires only one request to the server and WSDL generates a smaller one which contains URLs for the more detailed information that requires more requests to the server (if required)
- They are slightly different in using XML to provide information
Now that the first question is answered, answering the second one is easier:
If you are using Visual Studio as your IDE for development it can generate proxy client classes for both and if you are using svcutil.exe to generate them it can also generate them so the answer lies in the slight differences. You better use WSDL since it is easier to check in a simple web browser and only use MEX for when you need to publish meta-data through tcp and named pipes channels or for you software there is a benefit that the whole meta-data is read only once.