我正在按照下一页中的示例进行操作。http://msdn.microsoft.com/en-us/library/aa395224.aspx但运行时出现以下错误
在服务 MyServiceLibrary 实施的合同列表中找不到合同名称“IMetadataExchange”。将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost 以启用对此协定的支持。
MyServiceHostFactory 几乎是从该页面复制的,我将其添加到我的路由表中,如下所示。
RouteTable.Routes.Add(new ServiceRoute("V1", new MyServiceHostFactory(), typeof(MyServiceLibrary)));
我的配置文件
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
如果我将配置更新(如下)添加到我的配置文件中,服务会运行,但这会使其找到 ServiceMetaDataBehaviour 并真的使整个 SelfDescribeingServiceHost 变得多余?
ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find<ServiceMetadataBehavior>();
配置
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>