Domain Label contains illegal character ':'

229 Views Asked by At

I am using Sharp.XMPP library for FCM. I can connect fine and it receives Upstream messages without issues. However, sending ack back to server has a response of Error Code 400 with following details

<JIDMalformed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
<text>"Malformed JID 'XXXXXX:XXXXXXXXXXXXX-XXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXX_XXXXX_XXXXX-XXXXXXXXXXXXXXXXXXX': domain label contains illegal character ':'"</text>

whereas the Xs replace the device registration token from which the Upstream message was received. The code I'm using to form a message and send:

Sharp.Xmpp.Im.Message x = new Sharp.Xmpp.Im.Message(vFrom);
x.Data.SetAttribute("message_id", vMessageID);
x.Data.SetAttribute("message_type", "ack");
cl.SendMessage(x);

The string vFrom contains the device_token. I can not replace : as it is an essential part of device token and \: does not escape it either. What is the correct way of using colon in XML formats?

1

There are 1 best solutions below

0
Mashal Rashid On BEST ANSWER

The issue here is that you've added Attributes to <data> tag whereupon they should be Elements to <gcm>

var msg = Xml.Element("message");
var elem = Xml.Element("gcm" ,"google:mobile:data"); //the gcm tag with xmlns attribute
Xml.Child(msg, elem); //assign child to message tag
var data = new {to = vFrom; message_id = vMessageID, message_type = "ack"};
JavaScriptSerializer serializer = new JavaScriptSerializer();
elem.Text(serializer.Serialize(data)); //not adding attributes
cl.SendMessage(new Sharp.Xmpp.Im.Message(new Sharp.Xmpp.Core.Message(data: elem)));

This here is an improved version of Sharp.XMPP for FCM. It includes the class Sharp.Xmpp.Core.Message that is probably not committed to github. This might help clarify.