【发布时间】:2017-03-20 06:18:45
【问题描述】:
我使用 WCF 客户端向 WCF Service 发送 msmq 消息,在 WCF Service 处理 msmq 消息之前,我想检查消息的正文。
检查 msmq 消息正文的内容后,我得到以下结果。
但是,我没能得到确切的字符串。
下面是WCF服务的定义
[ServiceContract]
public interface IMSMQService
{
[OperationContract(IsOneWay = true)]
void ShowMessage(string msg);
}
我使用下面的方法来检索消息体,它输出为空,如果我在ms上添加watch,我可以得到
"\0\u0001\0\u0001\u0004\u0002(net.msmq://vdi-v-tazho/private/TestQueue\u0003\aV\u0002\v\u0001s\u0004\v\u0001a\u0006V \bD\n\u001e\0��+http://tempuri.org/IMSMQService/ShowMessage@\u0017VsDebuggerCausalityData\bAhttp://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink�
//message.Formatter = new XmlMessageFormatter(new String[] { });
//StreamReader sr = new StreamReader(message.BodyStream);
string ms = "";
//while (sr.Peek() >= 0)
//{
// ms += sr.ReadLine();
//}
message.Formatter = new ActiveXMessageFormatter();
string result = System.Text.Encoding.UTF8.GetString(message.Body as byte[]);
StreamReader reader = new StreamReader(message.BodyStream);
ms = reader.ReadToEnd();
MessageBox.Show(ms);
【问题讨论】:
标签: wcf msmq netmsmqbinding msmq-wcf msmq-transaction