software you can take with you

Error msg "Header already present." pls help me out! thx!

Last post 12-28-2011 5:58 PM by alanjmcf. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-23-2011 4:25 AM

    • Open
    • Not Ranked
    • Joined on 12-20-2011
    • Posts 2

    Error msg "Header already present." pls help me out! thx!

    Code :

               SerialPort port = new SerialPort("COM19");
                port.Open();
                Stream bs = port.BaseStream;
                ObexClientSession session = new ObexClientSession(bs, UInt16.MaxValue);
                string filePath=@"d:\tmp\SyncML.xml";
                FileStream src = File.OpenRead(@"d:\tmp\SyncML.xml");

                String name = Path.GetFileName(filePath);
                StreamReader rdr = new StreamReader(src);
                //strm.Position = 0;
                string txt = rdr.ReadToEnd();

                ObexHeaderCollection headers = new ObexHeaderCollection();
                string type = "application/vnd.syncml+xml";
                byte[ typeByteArray = System.Text.Encoding.Default.GetBytes(type);
                byte[ bodyByteArray = System.Text.Encoding.Default.GetBytes(txt);
                session.Connect(ObexConstant.Target.SyncML);  //This throws exception.
                headers.Add(ObexHeaderId.Count, 1);
                headers.Add(ObexHeaderId.Name, name);
                headers.Add(ObexHeaderId.ConnectionId, session.ConnectionId);
                headers.Add(ObexHeaderId.Type, typeByteArray);
                headers.Add(ObexHeaderId.Body, bodyByteArray);

                session.Put(headers);

  • 12-28-2011 5:58 PM In reply to

    Re: Error msg "Header already present." pls help me out! thx!

    Can you copy and paste the exception here.

    LATER: I suspect the exception is occuring on the PUT.  ObexClientSession will send the correct Connection Id so there's no need to send it, so we'll get a duplicate there.  Also the rest of the PUT is too complex. :-)  Just do:

         ... ...
         session.PutFrom(src, name, type, src.Length));

    That should work... (untested!)

    (It also leave the contents unmodified, rather than the implicit read-as-utf8-send-as-ansi-codepage conversion happening in the code currently)

    EVEN LATER: From a quick glance at syncml_obex_v11_20020215.pdf it appears that no Name header is required, so just send null for the name parameter in the Put call.

Page 1 of 1 (2 items)
Copyright © 2001-2013 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting