设置enableWebScript时如何添加元数据支持?

时间:2011-01-07 23:36:54

标签: asp.net wcf

我正在尝试创建由ASP.NET托管的wcf服务(我之前做过,但现在我不能......)

在此步骤中,我想添加元数据支持。一旦我将以下端点添加到配置中:

<endpoint address="mex" behaviorConfiguration="McActivationApp.EnrollmentServiceAspNetAjaxBehavior"
 binding="mexHttpBinding" contract="IMetadataExchange" />

我遇到以下错误:

  

端点位于   'HTTP://MyPcName/MCActivation/EnrollmentService.svc/mex'   没有与无绑定   MessageVersion。   'System.ServiceModel.Description.WebScriptEnablingBehavior'   仅适用于   WebHttpBinding或类似的绑定。

我试图将'IMetadataExchange'合同更改为''。这会导致另一个错误:

  

端点位于   'HTTP://MyPcName/MCActivation/EnrollmentService.svc/mex'   没有与无绑定   MessageVersion。   'System.ServiceModel.Description.WebScriptEnablingBehavior'   仅适用于   WebHttpBinding或类似的绑定。

请注意,如何正确添加对元数据的支持?


这是完整的'system.serviceModel'部分。

<system.serviceModel>
 <behaviors>
   <endpointBehaviors>
    <behavior name="McActivationApp.EnrollmentServiceAspNetAjaxBehavior">
     <enableWebScript />
    </behavior>
   </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="McActivationApp.EnrollmentServiceAspNetAjaxBehavior">
        <serviceMetadata httpGetEnabled="True"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="McActivationApp.EnrollmentServiceAspNetAjaxBehavior"
    name="McActivationApp.EnrollmentService">
    <endpoint address="" behaviorConfiguration="McActivationApp.EnrollmentServiceAspNetAjaxBehavior"
     binding="webHttpBinding" contract="McActivationApp.EnrollmentService" />
    <endpoint address="mex" behaviorConfiguration="McActivationApp.EnrollmentServiceAspNetAjaxBehavior"
     binding="mexHttpBinding" contract="McActivationApp.EnrollmentService" />
   </service>
  </services>
 </system.serviceModel>
</configuration>

2 个答案:

答案 0 :(得分:2)

如果从服务标记中删除behaviorConfiguration="McActivationApp.EnrollmentServiceAspNetAjaxBehavior"会发生什么。我也会尝试给行为赋予独特的名称,这可能会导致一些混乱。

答案 1 :(得分:1)

我为解决问题所做的工作:创建新的WcfServiceLibrary项目并分析它的应用程序配置。

基于此,我做了以下几点:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="McActivationApp.EnrollmentServicBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
    <endpoint address="" binding="webHttpBinding" contract="McActivationApp.EnrollmentService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.EnrollmentService" />
  </service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

主要区别在于我已将行为配置的规范从服务端点转移到服务本身。

此外,我删除了“端点”行为并使用了唯一的“服务”端点