Maybe I am mixing things, if this is the case, please let me know.
I want to provide a set of services through WCF regarding messages (this is an example). In this set I am going to have a “sendMessage” service and a “receiveMessage” service.
For the sendMessage, I want to use MSMQ, so the user can send the message to 100.000 other users and this will be processed in background.
For the receiveMessage I do not want to use MSMQ because I want the user to be served when he makes the request and get the response (MSMQ, in this case, is oneway).
I am using this code to start my host in an example 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 looks like this
[ServiceContract(SessionMode=SessionMode.Allowed)]
[DeliveryRequirements(QueuedDeliveryRequirements = QueuedDeliveryRequirementsMode.Allowed)]
public interface IContract
{
[OperationContract(IsOneWay = true)]
void SendData(string msg);
}
When the client invokes 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 which receives directly the message from the client (no queue in the middle).
The client would have only one web reference and if he calls service.SendData() the message is sent to the queue and if the client calls service.NetMethod() the service receives the message directly. This way it would be transparent for the client side developer if the service is using a queue or not and I would be able to group the services regarding their functions and not mechanisms. Would that be possible to make?
Thanks,
Oscar
WCF allows you to expose the same service contract across mixed transport bindings. For example, your service class has two operations, one one-way, and one request-response. You can expose this service across net.tcp:// and http:// on two endpoints (with different URIs).
However, what you want to do is have the different operations on your service contract exposed over different transports, and as far as I know WCF does not allow this.
The problem you have is that, as you say, the bi-directional operation cannot be supported under the msmq binding. So you would not be able to expose your entire contract across http and msmq simultaneously.
Is there any reason you cannot define two service contracts and host them in the same servicehost, as described here?