none
WCF+MSMQ,服务出现异常,自动停止服务 RRS feed

  • 问题

  • 开发环境 :

      服务机器:windows server 2003, msmq3.0。队列使用专用队列

      客户机器:win xp, msmq3.0。专用队列

    问题描述:

       客户端写消息到该机器的传出队列。服务启动后,该机的传出队列与客户机器的传出队列建立连接,然后从服务机器的专用队列中读取消息。当服务读取消息后,发生异常时,服务就停止工作,不再读取消息。客户端的消息也写不进服务队列。请问下是什么原因,有何解决方法?

    程序代码和配置:

    契约:

        [ServiceContract]
        public interface IContract
        {
            [OperationContract(IsOneWay=true)]
            void DealOrder(OrderInfo order);
        }

    服务业务处理:

    public class OrderService : IContract
        {
            [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true, AutoDisposeParameters = true)]
            public void DealOrder(OrderInfo order)
            {
                try
                {
                    Process(order.OrderID);
                    Random r = new Random();
                    int n = r.Next(1, 10);

                    if (n % 2 == 0)
                    {
                        throw new Exception("自定义异常");
                    }
                }
                catch (Exception ex)
                {
                    throw new FaultException<Exception>(ex);
                }
                finally
                {
                    System.Threading.Thread.Sleep(100);
                }
            }

    }

    服务配置:

      <system.serviceModel>
        <diagnostics performanceCounters="All"></diagnostics>
        <services>
          <service behaviorConfiguration="MessageBusServiceBehavior" name="MessageBus.Service.OrderService" >
            <endpoint address="net.msmq://192.168.1.189/private/MessageBusService"
                          binding="netMsmqBinding" bindingConfiguration="msmqBindConfig"
                          contract="MessageBus.Contract.IContract"/>
          </service>
        </services>
        
        <behaviors>
          <serviceBehaviors>
            <behavior name="MessageBusServiceBehavior" >
              <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"  />
              <serviceMetadata/>
              <serviceDebug includeExceptionDetailInFaults="true" />
              <dataContractSerializer maxItemsInObjectGraph="6553600"/>
              <serviceTimeouts transactionTimeout="00:01:00"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <netMsmqBinding>
            <binding name="msmqBindConfig" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
                     deadLetterQueue="System" durable="true" exactlyOnce="true" maxReceivedMessageSize="655360" maxRetryCycles="2" receiveErrorHandling="Fault"
                     receiveRetryCount="0" retryCycleDelay="00:30:00" timeToLive="1.00:00:00" useSourceJournal="true" useMsmqTracing="true"
                     queueTransferProtocol="Native" maxBufferPoolSize="819200" useActiveDirectory="false">
              <security mode="None">
                <transport msmqAuthenticationMode="None" />
                <message clientCredentialType="None" />
                
              </security>
            </binding>
          </netMsmqBinding>
        </bindings>
      </system.serviceModel>

    2012年10月12日 9:12

全部回复