Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 812207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:10:03+00:00 2026-05-15T01:10:03+00:00

I’m exploring MSMQ services, and I wrote a simple console client-server application that sends

  • 0

I’m exploring MSMQ services, and I wrote a simple console client-server application that sends each of the client’s keystrokes to the server. Whenever hit a control character (DEL, ESC, INS, etc) the server understandably throws an error. However, whenever I type a space character, the server receives the packet but doesn’t throw an error and doesn’t display the space.

Server:

namespace QIM
{
    class Program
    {
        const string QUEUE = @".\Private$\qim";
        static MessageQueue _mq;
        static readonly object _mqLock = new object();
        static XmlSerializer xs;

        static void Main(string[] args)
        {
            lock (_mqLock)
            {
                if (!MessageQueue.Exists(QUEUE))
                    _mq = MessageQueue.Create(QUEUE);
                else
                    _mq = new MessageQueue(QUEUE);
            }
            xs = new XmlSerializer(typeof(string));
            _mq.BeginReceive(new TimeSpan(0, 1, 0), new object(), OnReceive);
            while (Console.ReadKey().Key != ConsoleKey.Escape) { }
        }

        static void OnReceive(IAsyncResult result)
        {
            Message msg;
            lock (_mqLock)
            {
                try
                {
                    msg = _mq.EndReceive(result);
                    Console.Write(".");
                    Console.Write(xs.Deserialize(msg.BodyStream));
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                }
            }
            _mq.BeginReceive(new TimeSpan(0, 1, 0), new object(), OnReceive);
        }
    }
}

Client:

namespace QIM_Client
{
    class Program
    {
        const string QUEUE = @".\Private$\qim";
        static MessageQueue _mq;

        static void Main(string[] args)
        {
            if (!MessageQueue.Exists(QUEUE))
                _mq = MessageQueue.Create(QUEUE);
            else
                _mq = new MessageQueue(QUEUE);
            ConsoleKeyInfo key = new ConsoleKeyInfo();
            while (key.Key != ConsoleKey.Escape)
            {
                key = Console.ReadKey();
                _mq.Send(key.KeyChar.ToString());
            }
        }
    }
}

Client Input:

Testing, Testing…

Server Output:

.T.e.s.t.i.n.g.,..T.e.s.t.i.n.g……

You’ll notice that the space character sends a message, but the character isn’t displayed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:10:04+00:00Added an answer on May 15, 2026 at 1:10 am

    Your issue is not with MSMQ, it’s with the XmlSerializer class. See:

    var key = Console.ReadKey();
    
    XmlSerializer s = new XmlSerializer(typeof(string));
    
    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
    {
        s.Serialize(ms, key.KeyChar.ToString());
    
        ms.Position = 0;
    
        var foo = (string)s.Deserialize(ms);
    }
    

    If you type a space in the console, you’ll see that key.KeyChar.ToString() yields " ", but foo is equal to "". Because of the default implementation of XmlReader, the XmlSerializer class considers a string of only whitespace to be empty; if the string contains any other characters, both leading and trailing spaces are preserved. The whitespace does get serialized, but deserializing it turns it into an empty string.

    Use this instead:

    Console.Write(
        s.Deserialize(System.Xml.XmlReader.Create(msg.BodyStream, 
                                              new System.Xml.XmlReaderSettings() 
                                              { 
                                                  IgnoreWhitespace = false 
                                              })));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.