【问题标题】:IMetadataExchange MEX endpoint error when hosting WCF service in console application在控制台应用程序中托管 WCF 服务时出现 IMetadataExchange MEX 终结点错误
【发布时间】:2010-11-21 12:36:56
【问题描述】:

我有 WCF 服务。我正在尝试在控制台应用程序中托管服务。

我正在遵循所有指示here

现在一切正常,但运行时出现异常。

在服务索引器实施的合同列表中找不到合同名称“IMetadataExchange”。将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost 以启用对此合同的支持。

现在在指示中,我被指示添加

<endpoint binding="mexHttpBinding" bindingConfiguration=""
name="http://localhost:8080/myservice/MEX/" contract="IMetadataExchange" />

我的 WCF 服务或主机控制台应用程序中的任何位置都没有 IMetadataExchange。

异常从何而来?有没有我遗漏的参考资料?

这是我的控制台程序

namespace WcfConsoleHost
{
    class Program
    {
        static void Main(string[] args)
        {
            Type type = typeof(myservice);
            using (ServiceHost host = new ServiceHost(type))
            {

                host.Open();
                Console.WriteLine("The service is available. Press any key...");
                Console.ReadKey();
                host.Close();
            }
        }
    }
}

我的 WCF 服务只有一个带有合同的接口,然后是 myservice 类中的实现。

下面是我的整个 app.config。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceMetadata />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="myservice">
                <endpoint address="http://localhost:8080/myservice/"
                 binding="basicHttpBinding"
                    bindingConfiguration="" contract="myservice.Ims" />
                <endpoint binding="mexHttpBinding" bindingConfiguration=""
                 address="http://localhost:8080/myservice/MEX/"
                    contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
</configuration>

【问题讨论】:

    标签: .net wcf exception-handling wcf-binding wcf-configuration


    【解决方案1】:

    mex 端点的地址属性错误...它应该是地址,而不是名称。

    【讨论】:

    • 我解决了这个问题!此外,我认为实际上是服务标签中缺少 behaviorConfiguration="IndexerServiceBehavior"。
    猜你喜欢
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 2017-07-01
    相关资源
    最近更新 更多