---
title: "How do you enable metadata exchange (WSDL) in a WCF service?"  
description: "How do you enable metadata exchange (WSDL) in a WCF service?"  
author: "ICSM Computer"  
published: 2025-05-27  
updated: 2025-05-27  
canonical: https://www.mindstick.com/interview/34173/how-do-you-enable-metadata-exchange-wsdl-in-a-wcf-service  
category: "c#"  
tags: ["c#", "wcf"]  
reading_time: 3 minutes  

---

# How do you enable metadata exchange (WSDL) in a WCF service?

To **enable metadata exchange (WSDL)** in a **WCF service**, you need to:

1. **Enable metadata publishing** in the service behavior.
2. **Add a MEX (Metadata Exchange) endpoint**.
3. Optionally, enable **HTTP GET access** for easier browser-based discovery.

## Step-by-Step: Enabling WSDL in WCF

### 1. Define the Service and Base Address

```xml
<system.serviceModel>
  <services>
    <service name="MyNamespace.MyService">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/MyService" />
        </baseAddresses>
      </host>
```

### 2. Add the MEX Endpoint

```xml
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
```

This allows metadata exchange over HTTP using `mexHttpBinding`.

### 3. Enable Metadata Behavior

```xml
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="MetaBehavior">
        <!-- Enable metadata publishing -->
        <serviceMetadata httpGetEnabled="true" />
        <!-- Optional: Include exception details in faults -->
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
```

### 4. Link the Behavior to Your Service

Make sure the service references the behavior:

```xml
<service name="MyNamespace.MyService" behaviorConfiguration="MetaBehavior">
```

## Full Example Configuration

```xml
<system.serviceModel>
  <services>
    <service name="MyNamespace.MyService" behaviorConfiguration="MetaBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/MyService" />
        </baseAddresses>
      </host>

      <endpoint address="" binding="basicHttpBinding" contract="MyNamespace.IMyService" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="MetaBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
```

## Verifying Metadata Access

- You should see the WSDL XML if everything is configured correctly.
- Browse to:

```plaintext
http://localhost:8080/MyService?wsdl
```

## Answers

### Answer by ICSM Computer

To **enable metadata exchange (WSDL)** in a **WCF service**, you need to:

1. **Enable metadata publishing** in the service behavior.
2. **Add a MEX (Metadata Exchange) endpoint**.
3. Optionally, enable **HTTP GET access** for easier browser-based discovery.

## Step-by-Step: Enabling WSDL in WCF

### 1. Define the Service and Base Address

```xml
<system.serviceModel>
  <services>
    <service name="MyNamespace.MyService">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/MyService" />
        </baseAddresses>
      </host>
```

### 2. Add the MEX Endpoint

```xml
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
```

This allows metadata exchange over HTTP using `mexHttpBinding`.

### 3. Enable Metadata Behavior

```xml
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="MetaBehavior">
        <!-- Enable metadata publishing -->
        <serviceMetadata httpGetEnabled="true" />
        <!-- Optional: Include exception details in faults -->
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
```

### 4. Link the Behavior to Your Service

Make sure the service references the behavior:

```xml
<service name="MyNamespace.MyService" behaviorConfiguration="MetaBehavior">
```

## Full Example Configuration

```xml
<system.serviceModel>
  <services>
    <service name="MyNamespace.MyService" behaviorConfiguration="MetaBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/MyService" />
        </baseAddresses>
      </host>

      <endpoint address="" binding="basicHttpBinding" contract="MyNamespace.IMyService" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="MetaBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
```

## Verifying Metadata Access

- You should see the WSDL XML if everything is configured correctly.
- Browse to:

```plaintext
http://localhost:8080/MyService?wsdl
```


---

Original Source: https://www.mindstick.com/interview/34173/how-do-you-enable-metadata-exchange-wsdl-in-a-wcf-service

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
