wcf msmq

 

service:

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);
            }
        }
    }
}

config

   <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:

        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:

client side have to install msmq service

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

 

https://www.cnblogs.com/enternal/p/5275447.html

 

转载于:https://www.cnblogs.com/marcocao/p/10131027.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值