Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Sunday, 27 September 2009

WCF Metadata Exchange (mex)

To my understanding, metadata exchange (in WCF) means whether the service will offer a WSDL or other types of metadata to a client to enable them to autogenerate a proxy for the web services.

By default it is not enabled to exchange metadata, so its something that has to be added as an extra endpoint.

The endpoint works as any other endpoint (see link), where the contract type IMetadataExchange is mandatory. This contract type is a predefined service contract which is found in System.ServiceModel.Description namespace.

The endpoint can have different kinds of bindings like MexHttpBinding (meaning HTTP), MexHttpsBinding (HTTPS)

From a web service perspective it seems a bit strange that you would have to specifically add an endpoint to allow metadata transfer. But since WCF is a general communication framework I'm sure there is lots of places where its better not to have a service sending out metadata.

WCF service endpoint

An endpoint is defined by an address, contract and binding.

A address can be defined in the following ways (in the config file) either as implicit using the base address (which is required to be defined):

<endpoint binding="basicHttpBinding" name="basicHttp" contract="Host.ItecneckService" />

Which would make the service address: "http://localhost:8000/tecneck/"
or as a relative url:

<endpoint address="TecneckService" binding="basicHttpBinding" name="basicHttp" contract="Host.ItecneckService" />

making the url: "http://localhost:8000/tecneck/TecneckService"

or full url:

<endpoint address="http://localhost:8000/tecneck/TecneckService" binding="basicHttpBinding" name="basicHttp" contract="Host.ItecneckService" />

The base address is added like this (under the <service> tag):
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/tecneck"/>
</baseAddresses>
</host>

A Service can have several endpoints but they have to be unique, and differ in either address, contract or transport protocol. There can be several reasons why a service would have multiple endpoints for example:


  • The service implements several contracts, which could each need their own endpoint

  • More the one protocol should be supported

  • same service must be accessible by clients with different binding requirements, possibly related to security, reliable messaging, or transactions.