简体   繁体   English

邮件未添加到我的MSMQ

[英]Messages not being added to my MSMQ

I am trying to run a MSMQ service for the 1st time. 我正在尝试第一次运行MSMQ服务。

I have copied an example from MSDN and I am trying to get it to work. 我已经从MSDN复制了一个示例,我正在尝试使其运行。

Everything runs OK and there are no errors. 一切运行正常,没有错误。 Yet when I go to inspect my MSMQ there are no message available/added. 但是,当我去检查MSMQ时,没有可用/未添加的消息。

I have used the Trace tool SvcTraceViewe.exe and there are no errors reported. 我已经使用了跟踪工具SvcTraceViewe.exe,并且没有错误报告。

This is my Service defined in a class DLL: 这是我在类DLL中定义的服务:

public class MotionSaver : IMotionSaver
{
    [OperationBehavior]
    public void MotionFrame(byte[] data)
    {
        // DO I NEED TO PUT ANTHING IN HERE??
    }
}

[ServiceContract]
public interface IMotionSaver
{
    //IsOneWay=true denotes that there will no return message from the server to the client.
    [OperationContract(IsOneWay = true)]
    void MotionFrame(byte[] data);
}

This is my Server host which calls the above DLL: 这是我的服务器主机,它调用上述DLL:

static void Main(string[] args)
{
    try
    {
        using (ServiceHost host = new ServiceHost(typeof(MotionSaver)))
        {
            //Path of the Queue. Here we are creating a private queue with the name VishalQ 
            //where all our message would be stored, if server is unavialable.
            string queueName = ConfigurationManager.AppSettings["queueName"];
            //Checking whether the queue exists or not.
            if (!MessageQueue.Exists(queueName))
            {
                //If the queue doesnot exists it will create a queue with the name VishalQ
                //the second parameter false denotes that the queue would be a non transaction queue. If you want that your queue to be 
                //transaction then make the second parameter to true.
                MessageQueue.Create(queueName, true);
            }
            //finally opening the host to server the clients.
            host.Open();
            Console.WriteLine("Server is up and running on port 32578");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
    catch  (Exception ex)
    {
        Console.WriteLine(ex.ToString());
        Console.ReadKey();
    }
}

This is my app.config settings in the host app: 这是主机应用程序中我的app.config设置:

<configuration>
  <appSettings>
    <add key="queueName" value=".\private$\MotionSaverTest4" />
  </appSettings>

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "SdrConfigExample.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>


  <system.serviceModel>
    <diagnostics performanceCounters="All"/>
    <services>
      <service name="InformedMotion.Motion.MotionSaver" behaviorConfiguration="myBehavior">
        <!--Address attribute specifies the name of the MSMQ Queue.-->
        <endpoint name="motionQ" address="net.msmq://localhost/private/MotionSaverTest4" binding="netMsmqBinding" 
                  bindingConfiguration="myMSMQ"                
                  contract="InformedMotion.Motion.IMotionSaver">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.msmq://localhost/private/"/>
            <!--Both Mex and HttpBinding uses http://localhost:8888 port-->
            <add baseAddress="http://localhost:32578"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <!--The property exactlyOnce=false means that i am using non transactional queue. The property is by default true.-->
      <netMsmqBinding>
        <binding name="myMSMQ" exactlyOnce="true">
        <!--<binding name="myMSMQ" exactlyOnce="false" durable="false">-->
          <!--
                        If we donot set the security mode to none then the following error occurs.
                        Binding validation failed because the binding's MsmqAuthenticationMode property is set to 
                        WindowsDomain but MSMQ is installed with Active Directory integration disabled. 
                        The channel factory or service host cannot be opened.
                    -->
          <security mode="None"/>
        </binding>
      </netMsmqBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="myBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <!--This is for enabling an exception-->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>

This is the client app that call the service: 这是调用该服务的客户端应用程序:

static void Main(string[] args)
{
    wsMotionQ.MotionSaverClient ws = new MotionSaverClient();
    ws.MotionFrame(new byte[] { 1 });

    Console.WriteLine("All Wishes sent successfully");
    Console.ReadLine();
}

and this is my client app.config: 这是我的客户端app.config:

<configuration>
    <system.serviceModel>
        <bindings>
            <netMsmqBinding>
                <binding name="motionQ">
                    <security mode="None" />
                </binding>
            </netMsmqBinding>
        </bindings>
        <client>
            <endpoint address="net.msmq://localhost/private/MotionSaverTest4"
                binding="netMsmqBinding" bindingConfiguration="motionQ" contract="wsMotionQ.IMotionSaver"
                name="motionQ">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
</configuration>

I have checked that my message queue has been created. 我检查了我的消息队列是否已创建。

1). 1)。 How does a message get added to the queue? 如何将消息添加到队列中? What is the point of an empty method in my service? 我的服务中空方法的意义是什么? 2). 2)。 Why are my messages not being added? 为什么未添加我的消息?

Thanks 谢谢

NB NB

Changed code to this: 将代码更改为此:

[OperationBehavior]
public void MotionFrame(byte[] jpegData)
{
    using (Message msg = new Message())
    {
        msg.BodyStream = new MemoryStream(jpegData);
        msgQMissedData.Send(msg);
    }
}

You're just creating the queue, but you're not sending / receiving messages to/from it. 您只是在创建队列,但没有在队列中收发消息。

http://www.codeproject.com/Articles/5830/Using-MSMQ-from-C http://www.codeproject.com/Articles/5830/Using-MSMQ-from-C

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

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