Development Environment:
Win2008Sp2Vs2008Sp1
Add roles: Web Server (IIS7), Application Server (Message Queuing)
Add features: WCF Activation Msmq:Multicasting support
Confirm:Net. Msmq Listener Adapter Running
Because I use IIS7 to Host WCF and WCF uses multiple channel bindings, the web application in the WCF determines that the msmq binding is enabled.
Publisher implementation
Send Message msg to multicast address
Msg. Body = Your Object;
Code
1
[DataContract]
2 public class
RelMomInfo
3
{
4
[DataMember]
5 public string
GUID
6
{
7 get
;
8 set
;
9
}
10
[DataMember]
11 public string
StrMomInfo
12
{
13 get
;
14 set
;
15
}
16
}
17
18 # region Test Pub-Sub: Send multicase message of rmi
19 string multicastaddress = "224.0.255.1: 8123"
;
20 using (VAR queue = new messagequeue (string. Format ("formatname: multicast = {0 }"
, Multicastaddress )))
21
{
22 relmominfo RMI = new
Relmominfo ();
23 RMI. guid =
Guid. newguid (). tostring ();
24 RMI. strmominfo = "client sent ."
;
25
26 message MSG = new
Message ();
27 msg. Body =
RMI;
28
29 queue. Send (MSG, "Multicast MSG"
);
30
}
31
32 # endregion
33
Contract
Define a WCF contract
Code
Namespace RelSrvContract
{
[ServiceContract]
[ServiceKnownType (typeof (RelMomInfo)]
Public interface ISrvReceiveMomInfoContract
{
[OperationContract (IsOneWay = true, Action = "*")]
Void ReceiveMomInfo (MsmqMessage <RelMomInfo> rmi );
}
}
WCF services
WCF Service Code:
Code
Namespace SrvSubscriber
{
[AspNetCompatibilityRequirements (RequirementsMode =
AspNetCompatibilityRequirementsMode. Allowed)]
Public class SrvSubscriberOne: ISrvReceiveMomInfoContract
{
Public void ReceiveMomInfo (MsmqMessage <RelMomInfo> rmi)
{
RelMomInfo RMI = (RelMomInfo) rmi. Body;
RMI. strMomInfo = RMI. strMomInfo + "SrvReceiveOne Got it! ";
RelComm. SendMsgComm sm = new RelComm. SendMsgComm ();
Sm. SendRelMsg (RMI );
}
}
[Aspnetcompatibilityrequirements (requirementsmode =
Aspnetcompatibilityrequirementsmode. Allowed)]
Public class srvsubscribertwo: isrvreceivemominfocontract
{
Public void ReceiveMomInfo (MsmqMessage <RelMomInfo> rmi)
{
RelMomInfo RMI = (RelMomInfo) rmi. Body;
RMI. strMomInfo = RMI. strMomInfo + "SrvReceiveTwo Got it! ";
RelComm. SendMsgComm sm = new RelComm. SendMsgComm ();
Sm. SendRelMsg (RMI );
}
}
}
IIS7 Host two WCF subscribers
Iis7 host two WCF subscriptions
The code for SrvSubcriberOne. svc and SrvSubscriberTwo. svc is:
<% @ ServiceHost Language = "C #" Debug = "true" Service = "SrvSubscriber. SrvSubscriberTwo" %>
<% @ ServiceHost Language = "C #" Debug = "true" Service = "SrvSubscriber. SrvSubscriberOne" %>
Configure IIS7 to support SVC
You must manually add the *. svc extension to enable IIS7 for WCF support.
Open "Start | all programs | attachments | command prompt", enter "cd C: \ Windows \ Microsoft. NET \ Framework \ v3.0 \ Windows Communication Foundation", and press Enter.
Enter “servicemodelreg.exe-I, and press Enter.
Open "handler ing" in "Internet Information Service (IIS) manager" and you will see that IIS7 has added a ing to the *. svc extension.
IIS7OfThe Web server must be configured to support Msmq binding, and the Web Application of the Host Wcf subscription service must be configured to support Msmq binding .:
Web server needs to be configured to support Msmq
The Web Application needs to be configured to support Msmq and add it to the position of the circleNet. MSMQ
The two WCF subscription services are SrvSubcriberOne. svc SrvSubscriberTwo. svc. The two WCF services are respectively bound to different msmq
Configure the MSMQ and HOST to be bound to the WCF on IIS7
Configuring bindingconfig security is classified into None
Configure MSMQ:
Publisher sends the message through the multicast address 224.0.255.1: 8123. We will see this queue in the application server, we have created two non-transactional MSMQ queues for WCF binding and configured the multi cast address of these two queues as: 224.0.255.1: 8123.
Run publisherclient to send the message with the body as the relmominfo object to the multicast address. The two subscribe to WCF will get the message and execute it.
Note:
After compilation, the WCF does not run in the memory. You need to browse the IE File to make it work. You also need to refresh it after modifying web. config.
To be continued