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?
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.
Related
i am trying to send a HttpWebRequest with the following body :
string body = "{\"prompt\": \"MyText\",\"n\": 2,\"size\": \"256x256\",\"response_format\":\"b64_json\"}";
the request works perfectly with this body, but everytime i try to change "MyText" with a text from textbox, i get an error 400 from server.
i tried this (return error 400):
string body = "{\"prompt\":" +textBox1.Text+",\"n\": 2,\"size\": \"256x256\",\"response_format\":\"b64_json\"}";
any ideas ?
It is not recommended to build your JSON manually as you will highly expose to syntax errors due to missing/extra quotes, braces, etc especially when dealing with complex objects/arrays.
Using the libraries such as System.Text.Json or Newtonsoft.Json for the JSON serialization. This is safer and easier compared to building it manually.
using System.Text.Json;
var obj = new
{
prompt = textBox1.Text,
n = 2,
size = "256x256",
response_format = "b64_json"
};
string body = JsonSerializer.Serialize(obj);
using Newtonsoft.Json;
string body = JsonConvert.SerializeObject(obj);
I am trying to send MQ message from .NET application using amqmdnet library.
I put to queue simple message with two string properties like that:
var message = new MQMessage();
message.SetStringProperty("MessageID", Guid.NewGuid().ToString());
message.SetStringProperty("DocType", docTypeVal);
foreach (var b in content)
{
message.WriteByte(b);
}
var o = new MQPutMessageOptions();
var q = IBM_mqm.AccessQueue(ConnectionOptions.QueueNameOutput, MQC.MQOO_OUTPUT
+ MQC.MQOO_FAIL_IF_QUIESCING);
q.Put(message, o);
q.Close();
It works perfect when property "DocType" contains only latin symbols, digits and other general symbols.
message.SetStringProperty("DocType", "SomeEngText");
But when the property contains cyrillic symbols the message becomes unreadable. It's format becomes MQRFH2 despite the fact that I never set it. And named properties are empty.
message.SetStringProperty("DocType", "Договор купли продажи ТС");
When I am trying to read this message from my client an error 6106 MQRC_ENCODING_ERROR comes.
Some cyrillic values works fine (for example, "Кредитный договор"), but most of them breaks the message.
I tried to specify CCSID of the message like that:
message.CharacterSet = MQC.CODESET_UTF;
And also to set format:
message.Format = MQC.MQFMT_NONE;
But it didn't help.
How can I fix it?
I'm currently working on a new "dashboard like" website where I need to show all message from an exchange 2016 mailbox (like gmail or any bootstrap email client template).
Currently, I'm able to retrieve the messages from the mailbox without problem by using the EWS API.
My problem is I really don't know which format (XML or JSON) is better to return the message content (ID,Body,subject and DateTimeReceived). I tried to store all messages in a multidimenssional array and a jagged array but when I tried to serialize them in a JSON string, I always get an "Unexpected token" error.
So my two questions are:
1) Is it better to use XML format than JSON considering the message's body can be a very long string?
2) Is there a better way to achieve what I what to do rather than an array converted by a JQuery script?
PS: I'm working on Visual Studio 2017 and the language used is C# with a bootstrap dashboard template. Also, I am totally new to web development(language, good coding habits and etc) but not to C# programming.
Here's my function to extract all messages from the mailbox and return a multidimensional array :
public string[,] getEmail() {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.AutodiscoverUrl("testUser#myworkplace.com");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.UseDefaultCredentials = true;
PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView itemview = new ItemView(1000);
itemview.PropertySet = itempropertyset;
FindItemsResults < Item > findResults = service.FindItems(WellKnownFolderName.Inbox, itemview);
string[, ] emailArray = new string[findResults.TotalCount, 4];
int i = 0;
foreach(Item item in findResults.Items) {
message.Load(itempropertyset);
emailArray[i, 0] = message.Id.ToString();
emailArray[i, 1] = message.Subject;
emailArray[i, 2] = message.Body;
emailArray[i, 3] = message.DateTimeReceived.ToString();
i++;
}
return emailArray;
}
Any help would be appreciated.
If you're trying to get the data up to a web browser, you're most likely better off going with JSON. The browser has native code to parse JSON strings, and it's a very easy format both to create and parse.
That being said, you should still find a library to do the encoding for you. Pretty much all platforms will have some code to convert a set of nested Maps and Arrays to a JSON string, and that will help you avoid minor (but fatal) errors in actually formatting & parsing the document.
See also: JSON.stringify and JSON.parse
I am working with Amazon-SQS, I tried to retrieve approximate number of attributes from the queue but the response is null
I am using C# following is the code:
GetQueueAttributesRequest attReq = new GetQueueAttributesRequest();
attReq.QueueUrl = "Link to queue";
GetQueueAttributesResponse response = client.GetQueueAttributes(attReq);
Console.WriteLine("App. messages: "+ response.ApproximateNumberOfMessages);
I am getting null response from the request, I am sure there are messages in the queue as well.
You have to explicitly specify which attributes you would like to return from GetQueueAttributes. You didn't specify any, so it didn't return any.
Try simply adding ApproximateNumberOfMessages to the AttributeNames collection on GetQueueAttributesRequest:
GetQueueAttributesRequest attReq = new GetQueueAttributesRequest();
attReq.QueueUrl = "Link to queue";
attReq.AttributeNames.Add("ApproximateNumberOfMessages");
GetQueueAttributesResponse response = client.GetQueueAttributes(attReq);
Notes:
This property might be called AttributeName without the last s if you're on an older version of the AWSSDK. It looks like this changed between versions 1.x and 2.x.
Full list of attributes can be found in the API documentation
Using following SendEmailRequest containing characters with diacritics..
var sendRequest = new SendEmailRequest
{
Source = "Kůň <kun#test.com>",
Destination = destination,
Message = new Message
{
Subject = new Content(message.Subject),
Body = mailBody
}
};
..and dispatching it via Amazon SES results in sender being displayed incorrectly as KoH instead of Kůň in email client.
Is there a quick fix to get around this? How do I tell SES client to treat source as UTF-8? There is no such issue with subject.
The source code encoding must be declared.
Follow the link for more details about unicode:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd374081%28v=vs.85%29.aspx