2011-12-23 43 views
1

我有一个将消息写入队列(MSMQ)的旧式客户端。我想使用WCF服务从队列中选择XML消息。我跟随了一些MSFT文档,并在其他示例中使用过,但我似乎无法使其起作用。服务主机正在启动,但它不会触发我的进程并从队列中选择消息。最有可能的用户错误,只是不知道是什么。WCF MsmqIntegrationBinding - 不选择队列中的消息

我可以在队列中看到消息吗?

代码示例:

[ServiceContract] 
    [ServiceKnownType(typeof(XElement))] 
    public interface IMessageProcessor 
    { 
     [OperationContract(IsOneWay = true, Action = "*")] 
     void ProcessMessage(MsmqMessage<XElement> msg); 
    } 
    class MessageServiceClient : IMessageProcessor 
    { 
     [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)] 
     public void ProcessMessage(MsmqMessage<XElement> msg) 
     { 
      using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) 
      { 
       Console.WriteLine("Processing {0} ", msg.ToString()); 
       scope.Complete(); 
      } 

     } 

     static void Main(string[] args) 
     { 
      Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]); 
      // Create a ServiceHost for the CalculatorService type and provide the base address. 
      using (ServiceHost serviceHost = new ServiceHost(typeof(MessageServiceClient), baseAddress)) 
      { 
       // Open the ServiceHostBase to create listeners and start listening for messages. 
       serviceHost.Open(); 

       // The service can now be accessed. 
       Console.WriteLine("The service is ready."); 
       Console.WriteLine("The service is running in the following account: {0}"); 
       Console.WriteLine("Press <ENTER> to terminate service."); 
       Console.WriteLine(); 
       Console.ReadLine(); 

       // Close the ServiceHostBase to shutdown the service. 
       serviceHost.Close(); 
      } 
     } 
    } 

应用程序配置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <appSettings> 
    <!-- use appSetting to configure MSMQ queue name --> 
    <add key="QueueName" value=".\private$\MyMessageQueue" /> 
    <add key="baseAddress" value="http://localhost:8000/test/message" /> 
    </appSettings> 
    <system.serviceModel> 
    <services> 
     <service name="MessageServiceClient"> 
     <!-- .Net endpoint--> 
     <endpoint address="msmq.formatname:DIRECT=OS:.\private$\MyMessageQueue" 
        binding="msmqIntegrationBinding" 
        bindingConfiguration="DotNetBinding" 
        contract="WcfServiceClient.IMessageProcessor" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MessageServiceBehavior"> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceMetadata /> 
      <!--<serviceThrottling maxConcurrentCalls="20" maxConcurrentSessions="20" />--> 
      <serviceTimeouts /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <msmqIntegrationBinding> 
     <binding serializationFormat="ActiveX" name="ActiveXBinding" durable="false" exactlyOnce="false"> 
      <security mode="None" /> 
     </binding> 
     <binding serializationFormat="Xml" name="DotNetBinding" durable="false" exactlyOnce="false"> 
      <security mode="None" /> 
     </binding> 
     </msmqIntegrationBinding> 
    </bindings> 
    </system.serviceModel> 
</configuration> 

不知道我做错了吗?

--S

+0

您的服务名称不显示完全限定的名称。 – Rajesh 2011-12-23 10:24:50

回答

3

在你的配置以下元素需要,如下图所示:

<services> 
     <service name="WcfServiceClient.MessageServiceClient"> 
     <!-- .Net endpoint--> 
     <endpoint address="msmq.formatname:DIRECT=OS:.\private$\MyMessageQueue" 
        binding="msmqIntegrationBinding" 
        bindingConfiguration="DotNetBinding" 
        contract="WcfServiceClient.IMessageProcessor" /> 
     </service> 
    </services> 

你上面犯规服务名称包括一个命名空间,它应始终的一个完全合格的名称服务

+0

现货感谢!看着这个。 – scarpacci 2011-12-23 14:55:50