Benutzer:MovGP0/WCF/Metadata Exchange

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Metadata Exchange

[Bearbeiten | Quelltext bearbeiten]
  • disabled by default
  • exposing metadata over HTTP-GET only needs to be enabled

Enable MEX Declaratively

[Bearbeiten | Quelltext bearbeiten]
<system.serviceModel>
    <services>
        <service name="MyService" behaviorConfiguration="mex">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:8000/" />
                </baseAddresses>
            </host>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="mex">
                <serviceMetadata httpGetEnabled="true" 
                                 httpGetUrl="MyMexAddress" <!-- optional -->
                                 />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Enable MEX Imperatively

[Bearbeiten | Quelltext bearbeiten]
using(var host = new ServiceHost(typeof(MyService)))
{
    var metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
    if(metadataBehavior == null)
    {
        Debug.Assert(host.BaseAddresses.Any(baseAddress => baseAddress.Uri.Scheme == "http"));

        var newMetadataBehavior = new ServiceMetadataBehavior();
        newMetadataBehavior.HttpGetEnabled = true;
        host.Description.Behaviors.Add(newMetadataBehavior);
    }

    // ...

    host.Open();

    // ...
}