DCSIMG
WSDL vs MEX, knockout or tie? - Ido Flatow's Blog Veni Vidi Scripsi

Ido Flatow's Blog

Veni Vidi Scripsi

News

Have you heard me speak?
Powered
<style type='text/css' media='screen' id='sm_css'> #smix {overflow: visible;height: auto;border-radius: 10px;max-width: 250px;background-color: #323232;text-align: left;font-size: 12px;line-height: 16px;font-family:'Lucida Sans Unicode','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;} #smix a {color: #0056CC;text-decoration: none;} #smix .sm_head {color: #fff; line-height: 1em;font-size: 1.4em;padding: 10px;color: #fff;} #smix .sm_lanyard_wrapper {background-color: #fff;;clear: both;width: 97%;margin: 0 auto;margin-bottom: 0px;} #smix .sm_lanyard_content {padding: 7px;}#smix button.sm_rec, #smix a.sm_rec, #smix input[type=submit].sm_rec { padding: 6px 10px; -webkit-border-radius: 2px 2px;-moz-border-radius: 2px; border-radius: 2px; border: solid 1px rgb(153, 153, 153); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 255, 255)), to(rgb(221, 221, 221))); color: #333; text-decoration: none; cursor: pointer; display: inline-block; text-align: center; text-shadow: 0px 1px 1px rgba(255,255,255,1); line-height: 1; }#smix .sm_rec:hover { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(248, 248, 248)), to(rgb(221, 221, 221))); }#smix .sm_rec:active { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(204, 204, 204)), to(rgb(221, 221, 221))); }#smix .sm_rec.medium { padding: 3px 7px; font-size: 13px; }#smix .sm_rec span.icon.thumbs_up {background-position: 0px 36px;vertical-align: text-top;display: inline-block;margin-right: 4px;height: 18px;width: 16px;background-image: url(http://speakermix.com/images/new/thumbsold.png);}#smix .sm_rec:hover span.icon.thumbs_up {background-position: 0px 18px;} #smix .sm_events {padding:2px 0px 4px 0px;} #smix .sm_section {font-size: 10px; border-bottom: 1px solid silver; margin-bottom: 6px;} #smix .sm_subline {font-size:120%;margin-top:4px;font-weight:bold} #smix .powered {text-align: right} #smix .powered img {margin: 7px} </style>
Sela Technology Center

Advertisement

WSDL vs MEX, knockout or tie?

When teaching WCF I am always asked about the difference between getting the service’s metadata by using the WSDL’s http get url, and getting the metadata by calling the MEX endpoint.

To answer that question we first need to understand the different parts of the configuration that affect metadata creation.

The ServiceMetadata behavior

This behavior controls whether metadata is created for the service. When this behavior is used, the service is scanned, and metadata is created for the service’s contracts (a list of operations and types exposed by the service).

If the behavior is not used, no metadata will be created for the service, and you will not be able to create MEX endpoints.

The ServiceMetadata’s httpGetEnabled flag

This flag defines whether the metadata will be accessible by an http get request. If this attribute is set to true, then a default url will be created for the metadata (usually the service’s address with the suffix of  ‘?wsdl’). The url will lead you to a WSDL file containing the description of the service operations, but without the description of the data contracts – these files are accessible by different urls, usually the service’s url with the suffix of ‘?xsd=xsdN’. The list of these urls are pointed out from the WSDL file.

If you do not set this attribute to true, you will not be able to access the metadata using http get requests. If you prefer using https for the get requests, you can use the httpsGetEnabled attribute instead of the httpGetEnabled.

There are several other settings for the get options – you can read more about them on MSDN.

The MEX endpoint

MEX endpoints are special endpoints that allow clients to receive the service’s metadata by using SOAP messages instead of http get requests. You can create MEX endpoint that can be accessed through http, https, tcp, and even named pipes.

The response that you will receive when calling a MEX endpoint’s GetMetadata operation will include the content of the WSDL and all the XSD files that are linked to it.

So what exactly is the difference between MEX and WSDL?

There is no difference!

MEX and WSDL both output the same thing – a web service description language (WSDL) document, only MEX does it by getting a SOAP message over some transport (http, tcp, named pipes) and returning one message with all the parts, while the WSDL urls use http get requests and require sending several requests to get all the parts.

Don’t believe me?

The following diff diagram was produced by comparing the output of a MEX call to the output of the aggregated results gathered by calling all the WSDL related urls using http get:

image

As you can see, there are only several sections that are different between the files (marked in red and yellow), while most of the content is identical. Let’s look at one of these parts:

image

The red lines come from the MEX result, and the yellow lines from the WSDL file. The difference is because when using WSDL files, the rest of the XSD files are linked by using the <xsd:import> tag with the schemaLocation attribute. Since the MEX response includes all the XSD content in it, the import tag doesn’t include the location attribute.

As for the other different sections – they are different because the MEX response wraps each WSDL/XSD part with an xml element that does not appear in the aggregated files. These elements are part of the MEX standard declared by the W3C - surprise surprise, MEX is a W3C standard, it’s not a Microsoft proprietary spec.

So they are the same, still, which one to use?

In most cases there is no need for MEX endpoint – using WSDLs with http get is usually enough.

The “Add Service Reference” option in Visual Studio 2010 will work for both options. The same goes for the svcutil command line tool.

So when would I use MEX?

  1. If you want to make as less calls as possible to your service in order to get its metadata (one call instead of several).
  2. If you don’t want to use HTTP to get the metadata, but prefer using TCP or named pipes (not so common).
  3. If you want people to ask you why you declared a MEX endpoint.

So is it a knockout or a tie? I say tie.

kick it on DotNetKicks.com Shout it

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# August 10, 2011 11:16 AM

Jean-Michel Bezeau said:

Thanks for the good article, I will keep it for future reference. I had not understood by myself that the metadata was complete when using mex. In my organization, less calls is a good thing so I will be able to use that as an argument for mex endpoints.

# August 11, 2011 2:58 PM

Ido Flatow said:

MEX endpoint does not show in the WSDL files since it is a system endpoint. WSDL contains only the endpoints you define for your contracts. For example, it doesn't include UDP endpoints for Discovery.

# August 11, 2011 5:40 PM

WSDL vs MEX, knockout or tie? – Ido Flatow's Blog Veni Vidi Scripsi | Pici Blog said:

Pingback from  WSDL vs MEX, knockout or tie? &#8211; Ido Flatow&#039;s Blog Veni Vidi Scripsi | Pici Blog

# August 12, 2011 6:06 AM

Ido Flatow's Blog

Veni Vidi Scripsi

said:

This is the second post in the WCF 4.5 series, and this time we’ll talk about WSDL files. Previous posts

# September 17, 2011 7:04 PM

[??????????????] 2. ?????? ???????????? ?? WCF 4.5? ???????? WSDL-????????. [5] « ahriman' lair said:

Pingback from  [??????????????] 2. ?????? ???????????? ?? WCF 4.5? ???????? WSDL-????????. [5] &laquo; ahriman&#039; lair

# January 29, 2012 8:07 AM

[??????????????] 2. ?????? ???????????? ?? WCF 4.5? ???????? WSDL-????????. [4] « ahriman' lair said:

Pingback from  [??????????????] 2. ?????? ???????????? ?? WCF 4.5? ???????? WSDL-????????. [4] &laquo; ahriman&#039; lair

# January 29, 2012 8:16 AM

Ido Flatow's Blog

Veni Vidi Scripsi

said:

I was asked yesterday in the Hebrew C#/.NET Framework MSDN forums a tough question – is it possible to

# February 10, 2012 12:47 AM

Rahul said:

thank you for taking time to explain this for the benefit of others

# March 20, 2012 8:22 PM

Naveen Kok cha said:

Hey Ido,

Wondeful Article buddy. Really appreciate efforts put in and knowledge shared.

# June 11, 2012 11:48 PM

siva said:

ur teaching is good,but u can give any example for this one. it is very easy to understand.

# September 5, 2012 1:38 PM

Lewis said:

Really when someone doesn't understand after that its up to other viewers that they will help, so here it happens.

# October 30, 2012 10:27 AM

Vinod Satapara said:

Awesome!!!

# November 18, 2012 11:51 PM

vikash said:

many many dhanyavad(thanks) for this article...

# November 21, 2012 2:08 AM

NGGR HATER said:

SOUNDS LIKE SOME DUMB ASS SOB ROFL POSTED THIS WORTHLEASS PIECE OF CRAPOLA ARTICLE

# January 4, 2013 11:31 PM

p said:

Topic cleared

# February 12, 2013 9:33 AM

Mrunali said:

Good information. Thank you.

# March 16, 2013 11:02 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: