【问题标题】:How to add Metadata support when enableWebScript is Set?设置 enableWebScript 时如何添加元数据支持?
【发布时间】:2011-06-05 14:24:19
【问题描述】:

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

在这一步我想添加元数据支持。将以下端点添加到配置后:

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

我遇到以下错误:

端点在 'http://MyPcName/MCActivation/EnrollmentService.svc/mex' 没有与 None 的绑定 消息版本。 'System.ServiceModel.Description.WebScriptEnablingBehavior' 仅用于与 WebHttpBinding 或类似的绑定。

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

端点在 'http://MyPcName/MCActivation/EnrollmentService.svc/mex' 没有与 None 的绑定 消息版本。 '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>

【问题讨论】:

    标签: asp.net wcf


    【解决方案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>
    

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • +1 正确 - MEX 端点不能启用任何 WebScript 行为和类似的东西!
      • 您是否将 mex 端点的合同改回“IMetadataExchange”?使服务和端点行为的名称唯一并更新端点?
      • 不,我读到有可能(并且可能必须)使用“自己的”类来实现元数据交换合同。我不清楚为什么...但是(请参阅我自己的答案)它可以进行其他更改。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-27
      相关资源
      最近更新 更多