4

在测试 WCF Web 服务时看到可怕的请求错误页面?

在此处输入图像描述

好吧,不用担心,因为这个 StackOverflow 答案向您展示了如何打开详细的错误显示:WCF 数据服务 - 如何诊断请求错误?

但是……等等我们没有一个看起来像那样的 Web.Config。

我们的只有一个system.serviceModel,就是这样。

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
    <standardEndpoints>
        <webHttpEndpoint>
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
        </webHttpEndpoint>
    </standardEndpoints>
</system.serviceModel>

如果我们选择它并简单地添加以下内容:

<behaviors>
    <serviceBehaviors>
        <behavior name="DataServiceBehavior">
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

到最后,男孩是不是很不高兴:

在此处输入图像描述

更新/编辑

根据@burning_LEGION 和@Chris 的回答和评论(见下文),我现在有一个如下Web.Config所示的内容:

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
      <standardEndpoints>
    <webHttpEndpoint>
          <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" behaviorConfiguration="DataServiceBehavior"></standardEndpoint>
    </webHttpEndpoint>
      </standardEndpoints>

      <behaviors>
    <serviceBehaviors>
      <behavior name="DataServiceBehavior">
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
      </behaviors>
  </system.serviceModel>

但我收到服务器错误:

解析器错误消息:无法识别的属性“behaviorConfiguration”。请注意,属性名称区分大小写。

4

2 回答 2

5

感谢 Chris 和burning_Legion 指路。这是system.serviceModel我最终得到的结果,它成功地显示了错误详细信息。

这是每个@burning_LEGION 的回答,但在行为上没有 name 属性:

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
      <standardEndpoints>
    <webHttpEndpoint>
          <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
    </webHttpEndpoint>
      </standardEndpoints>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>
于 2012-08-09T09:35:41.763 回答
3

behaviors必须在标签中system.serviceModel

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
    <standardEndpoints>
        <webHttpEndpoint>
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
        </webHttpEndpoint>
    </standardEndpoints>   
    <behaviors>
       <serviceBehaviors>
           <behavior name="DataServiceBehavior">
              <serviceDebug includeExceptionDetailInFaults="true"/>
           </behavior>
       </serviceBehaviors>
    </behaviors> 
</system.serviceModel>
于 2012-08-09T08:25:03.820 回答