【问题标题】:How is this WCF service working?这个 WCF 服务是如何工作的?
【发布时间】:2012-11-21 15:33:20
【问题描述】:

我选择了一个几个月未接触过的项目,我使用该项目来学习 WCF,当我在 Visual Studio 中运行它时,它会打开一个页面,让我可以获取生成的 WSDL,我可以点击服务的代码。

但是当我查看 Web.config 时,那里几乎没有任何信息:

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

<system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

没有服务端点或任何东西,但它运行良好(至少在 Visual Studio 中),这是如何工作的?

【问题讨论】:

  • 您可以在代码中或通过配置文件配置 WCF。您是否在代码中完全配置了您的服务?
  • 不,没有任何配置,只是一个包含 3 个方法的 .svc 文件。
  • 在这种情况下@vcsjones 是正确的,您正在使用 WCF 的默认值运行。
  • 如果我将 web.config 替换为我配置的另一个 web.config,我怎么知道它正在被拾取而不是默认设置?

标签: .net visual-studio-2010 wcf


【解决方案1】:

WCF 3.x 的痛点之一是配置起来非常繁重,而且很难正确配置,即使对于最微不足道的服务也是如此。 WCF 4 引入了"Simplified Configuration" feature,因此需要以灵活性为代价进行几乎零配置。你仍然可以使用你想要的所有配置,这只是可选的。

更多详情on MSDN blogs:

因此,在 WCF 4.0 中,无需在 WCF 配置中添加任何内容即可创建 WCF 服务。 WCF 基础结构将负责为您的服务创建一个默认端点(以及默认绑定和默认行为)。

【讨论】:

  • 是否有一种简单的方法可以向上述 web.config 添加基本 HTTP 安全性,或者我是否必须实例化整个服务?我有一个不同的 web.config,其中包含绑定,但我不确定如何判断它正在被使用。
  • @OmarKooheji 整个简化的配置对我来说有点神秘。通常,只要我需要进行任何自定义配置,我就会添加 all 配置、端点和所有内容。
猜你喜欢
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-29
  • 2011-09-11
  • 1970-01-01
相关资源
最近更新 更多