Is it possible to have WCF services using MSMQ and WCF services not using MSMQ on the same host?

Maybe I am mixing things, if so, please let me know.

I want to provide a set of services through WCF regarding messages (this is an example). In this set, I will have the sendMessage service and the receiveMessage service.

For sendMessage, I want to use MSMQ, so the user can send a message to 100,000 to other users, and this will be processed in the background.

For receiving Message, I do not want to use MSMQ because I want the user to be serviced when he makes a request and receives a response (MSMQ, in this case, is turned on).

I use this code to run my host in the sample application

static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(Service), new Uri[] { new Uri("net.msmq://localhost/private/loadqueue"), new Uri("http://localhost:8383/") })) { host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true }); NetMsmqBinding binding = new NetMsmqBinding(); binding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None; binding.Security.Transport.MsmqProtectionLevel = System.Net.Security.ProtectionLevel.None; binding.ExactlyOnce = false; host.AddServiceEndpoint( typeof(IContract), binding, string.Empty); host.AddServiceEndpoint( typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); host.Open(); Console.WriteLine("service running"); Console.ReadLine(); } } 

The contract is as follows

 [ServiceContract(SessionMode=SessionMode.Allowed)] [DeliveryRequirements(QueuedDeliveryRequirements = QueuedDeliveryRequirementsMode.Allowed)] public interface IContract { [OperationContract(IsOneWay = true)] void SendData(string msg); } 

When the client calls the SendData service, the message is sent to the queue, and after that it is consumed by the service.

I would like to create a second service that receives a message directly from the client (no queue in the middle).

The client will have only one web link, and if it calls service.SendData (), the message is sent to the queue, and if the client calls service.NetMethod (), the service receives the message directly. Thus, the client-side developer will be transparent if the service uses the queue or not, and I can group services related to their functions, rather than mechanisms. Is it possible to do?

Thanks Oscar

+4
source share
1 answer

WCF allows you to issue the same service contract in mixed transport bindings. For example, your service class has two operations: one one-way and one response request. You can open this service through net.tcp: // and http: // at two endpoints (with different URIs).

However, what you want to do is various operations on your service contract exposed on different vehicles, and as far as I know, WCF does not allow this.

The problem is that, as you say, bidirectional operation is not supported with msmq binding. Thus, you cannot expose your entire contract through http and msmq at the same time.

Is there any reason why you cannot define two service contracts and place them in the same service as described here ?

+3
source

Source: https://habr.com/ru/post/1382924/


All Articles