2014-08-30 2 views
1

Я пытаюсь запустить службу MSMQ в первый раз.Сообщения, не добавляемые в мой MSMQ

Я скопировал пример из MSDN, и я пытаюсь заставить его работать.

Все работает нормально и ошибок нет. Тем не менее, когда я иду, чтобы проверить мой MSMQ, сообщение недоступно/не добавлено.

Я использовал инструмент Trace SvcTraceViewe.exe и сообщений об ошибках не было.

Это моя служба, определенная в классе 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); 
} 

Это мой хост-сервер, который вызывает выше 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(); 
    } 
} 

Это мои настройки 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> 

Это приложение-клиент, вызова службы:

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

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

и это мой клиент 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> 

Я проверил, что моя очередь сообщений была создана.

1). Как сообщение добавляется в очередь? В чем смысл пустого метода в моей службе? 2). Почему мои сообщения не добавляются?

С благодарностью

N.B.

Изменен код следующим образом:

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

ответ

1

Вы просто создавать очереди, но вы не отправлять/получать сообщения в/из него.

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

+0

Привет, я последовал пример на дэ этого: http://www.c-sharpcorner.com/UploadFile/17e8f6/msmq-in-wcf/. Он также не имеет кода в этой функции. Я педантичен, ожидая, что там будет код, или я должен использовать здравый смысл, что мне нужно добавить код LOL? –

+0

привет, я позаботился о том, чтобы включить этот код, но все равно он не работает ... –

+0

Привет, мне обязательно нужно добавить код в свою службу, чтобы добавить код (LOL). Я, наконец, получил его для работы, создав MSMQ вручную, а не через код, что заставляет его работать ... –

Смежные вопросы