Hello!
I am new to WCF and set up a very simple service program. All I want to do is have my service pick up the message off the queue and have my method simply display content of the message on the queue. I cannot find any examples of this. For example, putting a String message "Hello there!" on the queue, how can my service pull that off the queue using WCF and just say "You put on the queue {0}", currentMessage? Are there any classes that let you actually see the message in WCF?
Here is what I have so far:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using ServiceModelEx;
using System.Messaging;
using System.Diagnostics;
using System.Transactions;
using System.Configuration;
namespace MyTestServiceProg
{
[ServiceContract]
public interface IMyContract
{
[OperationContract(IsOneWay=true)]
void MyGetMessageMethod();
}
[ServiceBehavior(InstanceContextMode= InstanceContextMode.PerCall)]
public class MyService : IMyContract
{
[OperationBehavior(TransactionScopeRequired=true)]
public void MyGetMessageMethod()
{
Transaction transaction = Transaction.Current;
Debug.Assert(transaction.TransactionInformation.DistributedIdentifier != Guid.Empty);
}
static void Main(string[] args)
{
// Get MSMQ queue name from app settings in configuration
string queueName = ConfigurationManager.AppSettings["queueName"];
string baseAddress = ConfigurationManager.AppSettings["baseAddress"];
// Create the transacted MSMQ queue if necessary.
if (!MessageQueue.Exists(queueName))
MessageQueue.Create(queueName, true);
using (ServiceHost serviceHost = new ServiceHost(typeof(MyService), new Uri(baseAddress)))
{
serviceHost.Open();
Console.WriteLine("The MyService service is open...");
Console.WriteLine("Press enter to stop the service.");
Console.ReadLine();
serviceHost.Close();
}
}
}
}
Here is my app config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="queueName" value=".\private$\myfirstq" />
<add key="baseAddress" value="net.msmq://localhost/private/myfirstq"/>
</appSettings>
<system.serviceModel>
<services>
<service name="MyTestServiceProg.MyService" >
<endpoint
address="net.msmq://localhost/private/myfirstq"
binding="netMsmqBinding"
contract="MyTestServiceProg.IMyContract"
bindingConfiguration="NoMSMQSecurity"/>
</service>
</services>
<bindings>
<netMsmqBinding>
<binding name="NoMSMQSecurity" exactlyOnce="false">
<security mode="None"></security>
</binding>
</netMsmqBinding>
</bindings>
</system.serviceModel>
</configuration>
The service runs fine, but no clue how to get the message and see the contents of it, any ideas?
Thanks in advance!
H