【发布时间】: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