bsp; //同步接收,直到得到一条消息为止,如果消息队列为空,会一直阻塞
System.Messaging.Message msg = mq.Receive();
msg.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) });
this.txtReceive.Text = msg.Body.ToString();
}
}
}
测试一下,在Send Message文本框中随便一个Hello,点击Send Message按钮,再点击下面的Receive Message按钮,正常的话,下面的文本框会显示出Hello
然后在该解决方案中,再加一个web项目
default.aspx前端代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="webDemo._Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Send Message:<asp:TextBox ID="txtSend" runat="server"></asp:TextBox>
<asp:Button ID="btnSend" runat="server" OnClick="btnSend_Click" Text="btnSend" OnClientClick="return CheckData()" />
<script type="text/javascript">
function CheckData(){
var oSend = $get("<%=txtSend.ClientID%>");
if (oSend.value==""){
alert("请输入要发送的Message");
oSend.focus();
oSend.style.backgroundColor="#ffff99&quo |