【问题标题】:Confusion about default WCF project web.config layout关于默认 WCF 项目 web.config 布局的困惑
【发布时间】:2013-05-24 13:01:33
【问题描述】:

以下是 VS2012 中新 WCF 服务应用程序的 web.config 的默认布局。

让我感到困惑的是,它似乎与任何在线示例或教程都不匹配。没有定义端点或绑定,但可以调用服务。

我在尝试增加 MaxReceivedMessageSize 属性时遇到了问题 - 我用谷歌搜索了它,但不知道在哪里查看我的 web.config。

有人能指出为什么它的布局如此奇怪吗?

我希望它看起来更像 This SO question about setting MaxReceivedMessageSize 甚至像 Michelle Bustamante 的任何 WCF 教程,这是我最初学习 WCF 的方式。

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

    标签: wcf


    【解决方案1】:

    从 .NET 4.0 开始,WCF 引入了默认端点和绑定的概念,允许开发人员创建服务而无需在配置文件中定义一堆东西。

    发布的配置文件针对 4.5,这就是为什么您会看到如此裸露的 WCF 配置。如果您需要增加maxMessageSize,则需要在配置中明确定义。

    您可以通过将绑定定义设置为默认值(通过省略 binding 元素上的 name 属性)或创建端点并显式分配您通过 bindingConfig 属性定义的绑定配置来执行此操作.

    A Developer's Introduction to Windows Communication Foundation 4

    您也可以查看我之前的回答,其中包含示例:https://stackoverflow.com/a/16099054/745969

    【讨论】:

    • 谢谢蒂姆。我使用一些旧样式手动声明了所有内容并在那里进行了设置,效果很好:)
    猜你喜欢
    • 2013-02-01
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-21
    相关资源
    最近更新 更多