简体   繁体   English

WCF服务未处理MSMQ消息

[英]WCF Service not Processing MSMQ Message

I have a WCF Windows Service that checks for MSMQ messages. 我有一个WCF Windows服务,用于检查MSMQ消息。 It picks the messages up ok but the ProcessMSMQMessage event does not seem to get called. 它可以正常接收消息,但似乎未调用ProcessMSMQMessage事件。

Any ideas why this is? 任何想法为什么会这样? Have I set ProcessMSMQMessage event correctly? 我是否正确设置了ProcessMSMQMessage事件? Or am I missing something? 还是我错过了什么?

My code is below. 我的代码如下。 Thanks. 谢谢。

WCF Service Class... WCF服务类别...

public partial class MyService : ServiceBase
{

  private ServiceHost host;

  public MyService()
  {
    InitializeComponent();
  }

  protected override void OnStart(string[] args)
  {
    string queueName = ConfigurationManager.AppSettings["ProcessMsgQueueName"];
    if (!MessageQueue.Exists(queueName))
    {
      MessageQueue thisQueue = MessageQueue.Create(queueName, true);
      thisQueue.SetPermissions("Everyone", MessageQueueAccessRights.ReceiveMessage);
    }

    try
    {
      Uri serviceUri = new Uri("msmq.formatname:DIRECT=OS:" + queueName);

      // communicate to MSMQ how to transfer and deliver the messages
      MsmqIntegrationBinding serviceBinding = new MsmqIntegrationBinding();
      serviceBinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
      serviceBinding.Security.Transport.MsmqProtectionLevel = System.Net.Security.ProtectionLevel.None;

      serviceBinding.SerializationFormat = MsmqMessageSerializationFormat.Binary;

      host = new ServiceHost(typeof(MyService.Service1)); // add watcher class name
      host.AddServiceEndpoint(typeof(MyService.IService1), serviceBinding, serviceUri);
      host.Open();
    }
    catch (Exception ex)
    {
      EventLog.WriteEntry("SERVICE" + ex.Message, EventLogEntryType.Error);
    }
  }

  protected override void OnStop()
  {
    if (host != null)
     host.Close();
  }
}

IService1 Contract... IService1合同...

[ServiceContract(Namespace = "MyService")]
[ServiceKnownType(typeof(Events.Dashboard_Message))]
public interface IService1
{
  [OperationContract(IsOneWay = true)]
  void ProcessMSMQMessage(MsmqMessage<Events.Dashboard_Message> msg);
}

Service1 Class... Service1类...

public class Service1 : IService1
{
  [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
  public void ProcessMSMQMessage(MsmqMessage<Events.Dashboard_Message> msg)
  {
    string msgName = msg.GetType().Name;

    // send to eventlog
    EventLog.WriteEntry("MyService", msgName);  
  }
}

Got it working finally. 终于成功了。

The issue was in IService1 contract. 问题出在IService1合同中。 Needed to add Action = "*" . 需要添加Action = "*"

[OperationContract(IsOneWay = true, Action = "*")]

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

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