wcf msmq

 

service:html

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MsmqService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select MsmqService.svc or MsmqService.svc.cs at the Solution Explorer and start debugging.
    public class MsmqService : IMsmqService
    {
        public void SendMsg(string message)
        {
            string file = @"C:\Users\H261285\source\repos\WcfService1\WcfService1.Client\bin\Debug\test.txt";
            lock (file)
            {
                File.AppendAllText(file, message, Encoding.Default);
            }
        }
    }
}

configide

   <services>
     
      <service name="WcfService1.MsmqService">
        <endpoint address="net.msmq://localhost/private/test" binding="netMsmqBinding" contract="WcfService1.Contract.IMsmqService"
                   bindingConfiguration="NoneSecurity">
          
        </endpoint>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        
      <netMsmqBinding>
        <!--非事物性隊列因此-->
        <binding name="NoneSecurity" exactlyOnce="false" queueTransferProtocol="Native"> 
          <security mode="None"></security>
        </binding>
      </netMsmqBinding>
    </bindings>

 

client:this

        private static void DoMsmq()
        {
            var msmqBinding = new NetMsmqBinding();
            msmqBinding.Security.Mode =  NetMsmqSecurityMode.None;
            msmqBinding.ExactlyOnce = false;
            msmqBinding.QueueTransferProtocol = QueueTransferProtocol.Native;
            EndpointAddress endAddress = new EndpointAddress(new Uri("net.msmq://CH71LT2GS7LH2.global.ds.honeywell.com/private/test"));

            using (var factory = new ChannelFactory<IMsmqService>(msmqBinding, endAddress))
            {
                var proxy = factory.CreateChannel();

                proxy.SendMsg("Hello, Msmq!");
                Console.WriteLine("Msmq completed.");
            }
        }

note:url

client side have to install msmq servicespa

msmq message is consumed only after active msmq service, if host by iis, you can type url in browser to active itdebug

 

http://www.javashuo.com/article/p-whhjjoqr-gw.htmlcode

相關文章
相關標籤/搜索