如何通过ServiceBehavior配置启用WCF帮助页面?

时间:2014-01-28 21:21:11

标签: c# wcf web-services servicebehavior

我希望为使用<ServiceBehavior>而不是<EndpointBehavior>配置的WCF服务启用生成的帮助页面。 95%的搜索结果与<EndpointBehavior>有关,而我为<ServiceBehavior>找到的内容很少或者没有答案,缺乏详细信息,或者根本无法正常工作。

我不是IIS上托管的此服务的创建者,但其任务是启用该服务的帮助页面。根据我的发现,我应该能够在ServiceDebug元素下启用httpHelpPageEnabled属性,但这不会做任何事情,并且在浏览器中查看时添加httpHelpPageUrl会破坏整个服务。

无论如何

配置相关部分。

<system.serviceModel>  
  <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
  <bindings>
    <basicHttpBinding>
      <binding name="serviceBinding">
        <security mode="None">
        </security>
      </binding>
    </basicHttpBinding>
    <wsHttpBinding>
      <binding name="serviceWsBinding">
        <security mode="None">
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  <client />
  <services>
    <service behaviorConfiguration="ServiceBehavior" name="ServicesLib.Service">
      <endpoint listenUri="soap" name="soap" address="http://servicesdev.mySite.com/services/Service.svc/soap" binding="basicHttpBinding" bindingConfiguration="serviceBinding" contract="ServicesLib.IService" />
      <endpoint listenUri="soap12" name="soap12" address="http://servicesdev.mySite.com/services/Service.svc/soap12" binding="wsHttpBinding" bindingConfiguration="serviceWsBinding" contract="ServicesLib.IService" />
      <host>
        <baseAddresses>
          <add baseAddress="http://servicesdev.mySite.com/services" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <!-- These EndpointBehaviors aren't used, they are just here :? -->
    <endpointBehaviors>
      <behavior name="restBehavior">
        <webHttp />
      </behavior>
      <behavior name="soapBehavior">
        <webHttp helpEnabled="true" />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" externalMetadataLocation="../Services.wsdl" />
        <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

如果出于某种原因这不是正确的方法,也许有人可以指出我正确的方向托管自定义帮助页面?我一直在阅读this post关于从Windows服务托管一个解决方案的解决方案,但我不确定如何将此添加到WCF服务,该服务将以相同的方式与服务一起托管。

2 个答案:

答案 0 :(得分:1)

ServiceDebugElement HttpHelpPageEnabledHttpHelpPageUrl属性提供了启用自定义帮助页面的机制。但是,这些属性不会自动告诉服务器生成自定义页面。为了提供您自己的自定义帮助内容,您需要提供静态html帮助页面或返回自定义帮助页面的端点的URL(如您引用的文章中所述)。
的问候,

答案 1 :(得分:0)

<endpoint listenUri="soap" name="soap" address="http://servicesdev.mySite.com/services/Service.svc/soap" binding="basicHttpBinding" bindingConfiguration="serviceBinding" contract="ServicesLib.IService" behaviorConfiguration="restBehavior" />
      <endpoint listenUri="soap12" name="soap12" address="http://servicesdev.mySite.com/services/Service.svc/soap12" binding="wsHttpBinding" bindingConfiguration="serbviceWsBinding" contract="ServicesLib.IService" behaviorConfiguration="soapBehavior" />

    <endpointBehaviors>  
          <behavior name="restBehavior">
            <webHttp helpEnabled="true"/>
          </behavior>
          <behavior name="soapBehavior">
            <webHttp helpEnabled="true" />
          </behavior>
    </endpointBehaviors>