如何使用IMetadataExchange端点获取有关服务元数据的信息?

时间:2010-08-06 09:43:11

标签: wcf

如何使用IMetadataExchange端点获取有关服务元数据的信息?

我是否需要像在其他接口中那样在类中实现它?

请帮帮我......

3 个答案:

答案 0 :(得分:0)

不,只需添加公开IMetadataExchange的端点即可。你不必实现任何东西。

答案 1 :(得分:0)

框架将为您完成实施。

但是,您必须创建启用此功能的服务行为。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>

        <behaviors>
            <serviceBehaviors>
                 <!-- behavior that enables metadata exchanges -->
                <behavior name="mexGet">
                    <serviceMetadata httpGetEnabled="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <!-- assign the custom behavior here -->
            <service name="MyNamespace.MyImplementation"
                     behaviorConfiguration="mexGet">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:3849"/>
                    </baseAddresses>
                </host>
                <endpoint
                    address="MyService"
                    binding="wsHttpBinding"
                    contract="MyNamespace.MyServiceInterface"
                    >

                </endpoint>

                <endpoint
                    address="mex"
                    binding="mexHttpBinding"
                    contract="IMetadataExchange">

                </endpoint>
            </service>
        </services>
    </system.serviceModel>
</configuration>

答案 2 :(得分:0)

无需实施&#39; IMetadataExchange&#39;。只需添加端点:

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

重要的是,您必须声明serviceMetadata,否则您的IMetadataExchange将无法找到:

<behaviors>
    <serviceBehaviors>
        <behavior>
            <serviceMetadata />
        </behavior>
    </serviceBehaviors>
</behaviors>