简体   繁体   English

MSMQ & WCF 消息在私有队列中不可见

[英]MSMQ & WCF Messages not visible in private queue

There have been a few questions similar to this, and I am VERY new to MSMQ.有几个类似的问题,我对 MSMQ 很陌生。

I have been trying to link a ServiceContract and associated DataContract to MSMQ and have set up endpoints so that the DataContact message ends up in MSMQ.我一直在尝试将 ServiceContract 和关联的 DataContract 链接到 MSMQ,并设置了端点,以便 DataContact 消息在 MSMQ 中结束。

I have verified that the message is being correctly generated by the WCF service and I can also see that messages are in the Journal of the queue I am sending to, but not in the actual Queued Message area where I'd expect them.我已经验证了消息是由 WCF 服务正确生成的,我还可以看到消息在我发送到的队列的日志中,但不在我期望它们的实际排队消息区域中。

I am not using transactions at the moment, and I have set security to none.我目前没有使用交易,并且我已将安全设置为无。 I attach the relevant code, though my feeling is that I am missing something fundamental through ignorance of MSMQ.我附上了相关代码,尽管我的感觉是由于对 MSMQ 的无知,我错过了一些基本的东西。 Any pointers would be appreciated.任何指针将不胜感激。

Service & Data Contracts服务和数据合同

[DataContract] public class RegistrationMessage: IRegistrationMessage { [DataMember] public string EMailAddress { get; set; } [DataMember] public string FirstName { get; set; } [DataMember] public string LastName { get; set; } } [ServiceContract] public interface IRegistration { [OperationContract(IsOneWay = true)] void Register(RegistrationMessage message); }

app.config of the WCF host WCF主机的app.config

<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MetaDataBehaviour">
                    <serviceMetadata httpGetEnabled="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <netMsmqBinding>
                <binding name="msmq" 
                         deadLetterQueue="System" durable="true"
                         exactlyOnce="false" 
                         receiveContextEnabled="false" 
                         useMsmqTracing="true">
                    <security mode="None" />
                </binding>
            </netMsmqBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="MetaDataBehaviour" name="Client.AuthenticationService.RegistrationService">
                <endpoint address="net.msmq://localhost/private/AuthenticationQueue"
                    binding="netMsmqBinding" 
                    bindingConfiguration="msmq" name="msmq"
                    contract="Global.DomainModel.IRegistration" />
                <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080/Registration/" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>

I don't know WCF but I can comment on the MSMQ side.我不知道 WCF 但我可以评论 MSMQ 方面。

"I have verified that the message is being correctly generated by the WCF service and I can also see that messages are in the Journal of the queue I am sending to, but not in the actual Queued Message area where I'd expect them." “我已经验证了消息是由 WCF 服务正确生成的,我还可以看到消息在我发送到的队列的日志中,但不在我期望它们的实际排队消息区域中。”

This means that the message was delivered AND processed.这意味着消息已被传递和处理。
Journal messages associated with a queue are only created when the message has been delivered AND then read/received by an application.与队列关联的日志消息仅在消息已交付并随后由应用程序读取/接收时创建。
If a message was just delivered and not read/received then there would not be a journal message created yet and the original would remain in the destination queue.如果一条消息刚刚传递并且没有读取/接收,则还没有创建日志消息,原始消息将保留在目标队列中。
If a message was delivered but then purged/deleted, there would not be a journal message created as the original message was not read/received successfully by an application.如果消息已传递但随后被清除/删除,则不会创建日志消息,因为应用程序未成功读取/接收原始消息。

Cheers干杯
John Breakwell约翰·布雷克韦尔

Well, since no-one seems to have an answer to why the messages are being consumed, I have written a workaround in the service implementation which uses the native System.Messaging classes.好吧,由于似乎没有人知道为什么要使用消息,所以我在使用本机 System.Messaging 类的服务实现中编写了一个解决方法。 This is a shame because according to the documentation, one should be able to send a message to a queue without code (as long as the endpoints are described correctly).这是一种耻辱,因为根据文档,应该能够在没有代码的情况下将消息发送到队列(只要正确描述了端点)。

Here is the code I have used, for anyone in this predicament.这是我使用的代码,适用于处于这种困境的任何人。

In the host console project, I modified the App.Config endpoint by commenting out the net.msmq and adding a wsHttpBinding to make it a regular WCF service.在主机控制台项目中,我通过注释掉 net.msmq 并添加 wsHttpBinding 来修改 App.Config 端点,使其成为常规 WCF 服务。

        <services>
            <service behaviorConfiguration="MetaDataBehaviour" name="Client.AuthenticationService.RegistrationService">
<!--                <endpoint address="net.msmq://localhost/private/authenticationqueue"
                          binding="netMsmqBinding" 
                          bindingConfiguration="msmq" 
                          name="msmq"
                          contract="Global.DomainModel.IRegistration" /> -->
                <endpoint address="http://localhost:8080/Registration"
                          binding="wsHttpBinding"
                          bindingConfiguration=""
                          contract="Global.DomainModel.IRegistration" /> 
                <endpoint address="mex" 
                          binding="mexHttpBinding" 
                          name="mex" 
                          contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080/Registration/" />
                    </baseAddresses>
                </host>
            </service>

In the service implementation, I added the following (leaving the original Console.WriteLine statements in for testing purposes:在服务实现中,我添加了以下内容(保留原始 Console.WriteLine 语句用于测试目的:

    public void Register(RegistrationMessage message)
    {
        MessageQueue queue = new MessageQueue(@".\private$\authenticationqueue");
        Message msg = new Message();
        msg.ResponseQueue = queue;
        msg.Label = "AuthenticationMessage";
        msg.Body = message;
        queue.Send(msg);
        Console.WriteLine("e-mail: " + message.EMailAddress);
        Console.WriteLine("First Name: " + message.FirstName);
        Console.WriteLine("Last Name: " + message.LastName);
    }

This works perfectly and works as expected, hydrating the queue.这完美地工作并按预期工作,为队列补水。 Now I can write a workflow foundation service to consume it.现在我可以编写一个工作流基础服务来使用它。

Thanks to John for confirming the fact that messages were, in fact, being consumed.感谢 John 确认消息实际上已被消费。 I would give you a vote but my level is too low:)我会给你一票,但我的水平太低了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM