簡體   English   中英

MSMQ & WCF 消息在私有隊列中不可見

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

有幾個類似的問題,我對 MSMQ 很陌生。

我一直在嘗試將 ServiceContract 和關聯的 DataContract 鏈接到 MSMQ,並設置了端點,以便 DataContact 消息在 MSMQ 中結束。

我已經驗證了消息是由 WCF 服務正確生成的,我還可以看到消息在我發送到的隊列的日志中,但不在我期望它們的實際排隊消息區域中。

我目前沒有使用交易,並且我已將安全設置為無。 我附上了相關代碼,盡管我的感覺是由於對 MSMQ 的無知,我錯過了一些基本的東西。 任何指針將不勝感激。

服務和數據合同

[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); }

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>

我不知道 WCF 但我可以評論 MSMQ 方面。

“我已經驗證了消息是由 WCF 服務正確生成的,我還可以看到消息在我發送到的隊列的日志中,但不在我期望它們的實際排隊消息區域中。”

這意味着消息已被傳遞和處理。
與隊列關聯的日志消息僅在消息已交付並隨后由應用程序讀取/接收時創建。
如果一條消息剛剛傳遞並且沒有讀取/接收,則還沒有創建日志消息,原始消息將保留在目標隊列中。
如果消息已傳遞但隨后被清除/刪除,則不會創建日志消息,因為應用程序未成功讀取/接收原始消息。

干杯
約翰·布雷克韋爾

好吧,由於似乎沒有人知道為什么要使用消息,所以我在使用本機 System.Messaging 類的服務實現中編寫了一個解決方法。 這是一種恥辱,因為根據文檔,應該能夠在沒有代碼的情況下將消息發送到隊列(只要正確描述了端點)。

這是我使用的代碼,適用於處於這種困境的任何人。

在主機控制台項目中,我通過注釋掉 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>

在服務實現中,我添加了以下內容(保留原始 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);
    }

這完美地工作並按預期工作,為隊列補水。 現在我可以編寫一個工作流基礎服務來使用它。

感謝 John 確認消息實際上已被消費。 我會給你一票,但我的水平太低了:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM