【问题标题】:TransactionFlow in WCF from Visual Studio 2010 Express来自 Visual Studio 2010 Express 的 WCF 中的 TransactionFlow
【发布时间】:2014-09-17 07:26:46
【问题描述】:

我正在尝试使用免费的 Microsoft Visual Web Developer 2010 Express 开始使用 WCF 中的事务。它为我提供了创建“WCF 服务应用程序”的选项,但似乎并没有为我提供很多选项来托管它或配置不同的绑定。如果我 F5 项目我得到错误:

At least one operation on the 'Service' contract is configured with the TransactionFlowAttribute attribute set to Mandatory but the channel's binding 'BasicHttpBinding' is not configured with a TransactionFlowBindingElement. The TransactionFlowAttribute attribute set to Mandatory cannot be used without a TransactionFlowBindingElement.

我尝试将*/services/service/endpoint 配置添加到 web.config 中,但它似乎只是被忽略了。我还尝试将默认启动应用程序更改为 WcfSvcHost.exe,但此选项显示为灰色。我开始怀疑 Express 版本的一些失败,但我乐观地认为这只是我是个笨蛋。有没有我需要学习的技巧,或者在 Visual Studio 2010 的完整版上大放异彩就足以让我克服这个障碍并进入下一个障碍?

谢谢!

【问题讨论】:

  • 你能给我们看一下服务合同和配置文件吗?
  • 我正在使用“WCF 服务应用程序”中的 vanilla 示例,只是我向服务合同中的一项操作添加了 TransactionFlow 属性。 Web.config 中没有定义服务。我不知道发生了什么反射魔法,但即使我尝试使用 wsHttpBinding 设置端点(注意错误消息始终是 BasicHttpBinding)我也没有运气。

标签: wcf visual-studio-2010 visual-web-developer


【解决方案1】:

在不了解您的配置和服务合同的情况下,几乎不可能做出有针对性的回答。如果您认为您的配置被忽略,请确保 serviceendpoint/@contract 中使用的名称包含 CLR 命名空间。

WCF 4 使用了很好的简化配置,恕我直言,这使得实际配置比以前更加痛苦。您可以通过将其添加到您的网络配置来切换默认值:

<protocolMapping>
  <remove scheme="http" />
  <add scheme="http" binding="wsHttpBinding" bindingConfiguration="transactionFlowEnabled"/>
</protocolMapping>
<bindings>
  <wsHttpBinding>
    <binding name="transactionFlowEnabled" transactionFlow="true" />
  </wsHttpBinding>
</bindings>

这是一种解决方法,应该使用定义的绑定作为默认值,而不是 basicHttpBinding

【讨论】:

  • 你的两个答案都是正确的。谢谢!
【解决方案2】:

感谢 Ladislav 的建议,我能够通过在 Web.config 文件中添加以下条目来解决此问题:

<services>
  <service name="WcfService1.Service1">
    <endpoint
      address=""
      binding="wsHttpBinding"
      contract="WcfService1.IService1"
      />
  </service>
</services>

和:

<bindings>
  <wsHttpBinding>
    <binding transactionFlow="true"/>
  </wsHttpBinding>
</bindings>

【讨论】:

  • 你在服务器或客户端的 web.config 中哪里写的?
猜你喜欢
  • 1970-01-01
  • 2011-06-30
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多