【问题标题】:WCF service hosting failing while using netMsmqBinding binding with IIS hosting将 netMsmqBinding 绑定与 IIS 托管一起使用时 WCF 服务托管失败
【发布时间】:2012-04-02 21:18:30
【问题描述】:

使用 IIS 托管时的 WCF 服务失败。该服务的 web.config 是

<system.serviceModel>
    <bindings>
        <netMsmqBinding>
            <binding name="msmqbindingnontransactionalnonsecure" exactlyOnce="False">
                <security mode="None" />
            </binding>
        </netMsmqBinding>
    </bindings>
    <services>
        <service name="MsmqService.MsmqService">
            <endpoint address="net.msmq://localhost/private/msmqpoc/MsmqService.svc"  binding="netMsmqBinding" bindingConfiguration="msmqbindingnontransactionalnonsecure" contract="MsmqWCFService.IMsmqContract" />
        </service>
    </services>
    <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="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

服务合同是

[ServiceContract]
public interface IMsmqContract
{
    [OperationContract(IsOneWay = true)]
    void SendMessage(string message);
}

在 IIS 中托管服务时,显示以下消息:

Server Error in '/msmqpoc' Application.
--------------------------------------------------------------------------------

Binding validation failed because the binding's ExactlyOnce property is set to true while the destination queue is non-transactional. The service host cannot be opened. Resolve this conflict by setting the ExactlyOnce property to false or creating a transactional queue for this binding. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Binding validation failed because the binding's ExactlyOnce property is set to true while the destination queue is non-transactional. The service host cannot be opened. Resolve this conflict by setting the ExactlyOnce property to false or creating a transactional queue for this binding.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.      
Stack Trace:
[InvalidOperationException: Binding validation failed because the binding's ExactlyOnce property is set to true while the destination queue is non-transactional. The service host cannot be opened. Resolve this conflict by setting the ExactlyOnce property to false or creating a transactional queue for this binding.]

配置已经设置为exactOnce=false,不知道为什么会出现这个错误,有什么帮助吗?

【问题讨论】:

  • 您使用非事务队列有什么原因吗?
  • 这只是一个测试工作,计划是让非事务性队列工作,然后将队列更改为事务性和安全性。

标签: c# wcf iis exception-handling netmsmqbinding


【解决方案1】:

我只能推测您的服务没有选择正确的配置文件。我建议仔细检查一下。我看不出您发布的配置文件有任何问题。

有点偏离主题,我冒昧地考虑一下为什么要使用非事务性队列。您使用它们的唯一原因是您的整体架构是否可以容忍消息丢失。

例如,在某些低延迟系统中,消息最多只能在几秒钟内有价值,然后才会失效。因此,在这种情况下,您不需要使用事务队列。

如果您不能容忍消息丢失,则必须使用事务队列。

【讨论】:

  • 谢谢,这正是正在发生的事情。该服务没有选择命名配置,不知道为什么。我修改了配置并删除了绑定的名称,之后服务开始按预期工作。
  • hugh - 非事务队列是一个合法的选项,与 UDP 完全相同。在不知道 OP 意图的情况下尝试提出适合所有场景的最佳实践是没有帮助的。
  • @MickyDuncan 感谢您的评论。同意非事务性是一个合法的选择,因此我用一个不需要它的例子来说明我的猜测(使用事务性队列会更好地使用 OP)。在一般排队的好处中,人们认为最有吸引力的是持久性。我推测大多数人(当他们开始使用排队时)对持久性有内在的期望——我知道我有。如果不使用 DTC,MSMQ 根本无法提供持久性。因此,相反,我认为在这种情况下向 OP 指出这一点是有帮助的。
  • 同意。我喜欢 MSMQ 或与之相关的消息传递的一点是,它比 RPC 替代方案具有出色的可伸缩性。人们可能会说“一套免费的牛排刀”。 ;)
猜你喜欢
  • 2022-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-28
  • 2016-10-11
  • 1970-01-01
  • 2013-07-18
相关资源
最近更新 更多