在IIS上托管名为“SimpleWCF”的WCF服务;我在浏览器中手动浏览时出现以下错误;
在服务SimpleWCF实现的合同列表中找不到合同名称“IMetadataExchange”。将ServiceMetadataBehavior直接添加到配置文件或ServiceHost以启用对此合同的支持。
我无法理解这个错误的原因[还是新的]。
这是我的配置文件;
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="LargeData" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="SimpleWCF">
<endpoint address="http://localhost/Sample/SimpleWCF.svc" binding="basicHttpBinding" bindingConfiguration="LargeData" contract="SimpleWCF"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
答案 0 :(得分:2)
在您的配置中,您需要为您的行为提供有效的名称!
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
来自您的<service>
标记,您需要引用该行为:
<service name="SimpleWCF" behaviorConfiguration="serviceBehavior">
让它变得活跃。
如果您使用的是.NET 4 / WCF 4,您还可以定义默认行为 - 但是您需要完全省略name=
属性:
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
现在每个端点都将获得该端点行为,并且每个服务都将获得服务行为。