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