I got my url from the app. It begins with:
http://sn1.notify.live.net/throttledthirdparty/01.00/
and if I navigate to that URL using a browser, I get the message:
Microsoft Push Notification Server
I then grabbed the code provided by Microsoft.
http://msdn.microsoft.com/en-us/library/ff402545%28v=VS.92%29.aspx
If I take the C# code, and use it as is (changing only the URL, the Payload to be an empty byte array, and changing the "" string to Guid.NewGuid().ToString()
I get a 404 every time.
Because I don't get a 404 from by browser, the content must matter, and the push notification servers are dependent on content, so if I change it to a simple raw notification by removing the notification message and adding (as they recommend):
byte[] notificationMessage = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
sendNotificationRequest.Headers.Add("X-NotificationClass", "13");
I still get a 404 every time. I've tried doing toast notifications with the same result.
What am I doing wrong?
The reason you are getting a 404 is because the notificationMessage data you are sending isn't what it's expecting. Try this out and see if it works.
You can find a tutorial here:
http://benjii.me/2011/04/push-notifications-in-windows-phone-7-3-push-that-notification/
string template =
"<?xml version='1.0' encoding='utf-8'?>" +
"<wp:notification xmlns:wp='WPNotification'>" +
"<wp:toast>" +
"<wp:text1>{0}</wp:text1>" +
"<wp:text2>{1}</wp:text2>" +
"</wp:toast>" +
"</wp:notification>";
string toastXML = string.Format(template, "Testing", "This is a test");
byte[] notificationMessage = new UTF8Encoding().GetBytes(toastXML);
I ended up getting mine to work after binding toast notifications to the shell. I had a method which did it, but under some cases wasn't calling that method.
Related
This is a very strange issue we are having. We have a data processing service that posts a message to Teams channel using webhook every night. Everything was working fine until few days ago. The full message used to show up in the channel conversations.
But now the channel shows only the first line of the post. Please see the attached screenshot. All the previous posts from months ago also show only one line. This only happens on the desktop client and web portal.
The Teams app on both Android and iOS displays the full message, which is usually 7-8 lines long.
If I click on "New Conversation" and paste the same 7-8 lines it does show full message.
I have sifted through all settings of the desktop client and cannot find a solution. Cleared all caches also without success.
Appreciate any help.
Thank you
Edit - 12-9-22
Please see the JSON code below, but this is happening with older messages as well, that were posted months ago, which used to display fully. So I am guessing this has nothing to do with JSON itself and has to do with channel/chat window settings. As I mentioned before the posts show fully on both Android and IOS apps.
public async void SendTeamsMessage(string body, string projectName) {
string webhookUrl = MailSettings.Current.TeamsWebHookURL;
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri(webhookUrl);
TeamsMessage message = new TeamsMessage();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("Batch " + batch.BatchId.ToString() + " finished processing.");sb.AppendLine("Alert - " + projectName);
sb.AppendLine("Message from Service at " + DateTime.Now.ToString() + "\r\n");
sb.AppendLine("Message :" + body);
message.text = sb.ToString();
string serializeJson = JsonConvert.SerializeObject(message);
System.Net.Http.StringContent content = new System.Net.Http.StringContent(serializeJson, System.Text.Encoding.UTF8, "application/json");
await client.PostAsync(client.BaseAddress, content);
}
private class TeamsMessage {
public string text { get; set; }
}
Not sure what happened, but we can see the full messages now. Started working few minutes ago.
I have a java spring integration project that is receving emails through the below code:
ClassPathXmlApplicationContext ac =
new ClassPathXmlApplicationContext(
"/integration/gmail-imap-idle-config.xml");
DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);
inputChannel.subscribe(message -> {
org.springframework.messaging.Message<MimeMailMessage> received =
(org.springframework.messaging.Message<MimeMailMessage>) message;
log.info("content" + message);
List<String> sentences = null;
try {
} catch (Exception e) {
}
I get the email, and I can get the subject, but I can never actually extract the message body. How do I do this?
Thank you!
You have to use this option on the channel adapter:
simple-content="true"
See its description:
When 'true', messages produced by the source will be rendered by 'MimeMessage.getContent()'
which is usually just the body for a simple text email. When false (default) the content
is rendered by the 'getContent()' method on the actual message returned by the underlying
javamail implementation.
For example, an IMAP message is rendered with some message headers.
This attribute is provided so that users can enable the previous behavior, which just
rendered the body.
But still it is doubtful, since I see in case of GMail message it is never simple. The content is a MimeMultipart and we need to read its parts to get access to the real body.
So, this is how you should change your code as well:
log.info("content" + ((MimeMultipart) ((MimeMessage) message.getPayload()).getContent()).getBodyPart(0).getContent());
I've written a web API for sending and receiving data between a server and an app I'm working on.
It works fine for everything, but I've now found it won't let me send large strings. The strings are base64 strings which represent images, typically around 100kb in size.
The method I'm attempting is a multipart post, breaking the base64 string into chunks that can be sent successfully.
When I use this method, I get an error:
stream was reset: PROTOCOL_ERROR
Upon checking the database it seems the first string chunk sends successfully, but nothing more after that.
Can anyone shed some light on what's causing this to happen?
Relevant code is here:
First is the process for breaking the image into manageable chunks and posting it:
HTTPRequest req = new HTTPRequest();
IEnumerable<string> imgStrSplit = Split(img1byteArrayStr, 1000);
foreach (string s in imgStrSplit)
{
response = await req.SubmitImage("Test", s, "1");
}
And below is the SubmitImage() method of the HTTPRequest class:
public async Task<int> SubmitImage(string name, string imageString, string imgNum)
{
using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(new NativeMessageHandler()))
{
client.DefaultRequestHeaders.Add("Accept", "application/json");
int successResponse;
string address = $"https://myURL/SubmitImage?name=" + name + "&imageStr=" + imageString + "&imgNum=" + imgNum + "&curl=AYZYBAYZE143";
HttpResponseMessage response = await client.GetAsync(address);
successResponse = JsonConvert.DeserializeObject<int>(response.Content.ReadAsStringAsync().Result);
return successResponse;
}
Thanks.
Found a solution via this discussion.
The problem was in the fact that I was using the ModernHTTPClint NuGet package, as seen in this line of the SubmitImage method:
using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(new NativeMessageHandler()))
The NativeMessageHandler() is said to make connections work much faster, but apparently in some cases results in the PROTOCOL_ERROR I had encountered. By removing this part, I fixed the problem.
I am new in windows phone.Iam developing one app.in this app I want to send pushnotifications.how to send and receive pushnotifications in windows phone 8 using c#.please help me.
public string SendNotificationToWindows(string message, string notificationId)
{
try
{
//string subscriptionUri = "http://db3.notify.live.net/throttledthirdparty/01.00/AwYAAACKB3Noan4l%2bojXM5%2f3TDodPTegXbZxtTAzRktj3eWFOYmjjN1FPIdkuduXrwYZByFKLxy1gXy8rCmf1FSM6GH92rva7ecbQ%2b1%2bnGYxLWxoAI0GL03fZbV29p%2fu%2fJYrHQI%3d";
string subscriptionUri = "http://db3.notify.live.net/throttledthirdparty/01.00/aHR0cHM6Ly9zaW4ubm90aWZ5LndpbmRvd3MuY29tLz90b2tlbj1Bd1lBQUFEQjE1TzJMQWMlMmZBQldlUlpQendHMlglMmJRNWlPbzVUOVF3UUtXeUFQJTJic2clMmZFREhuSHM0bDBVN2tFN2prSXVJYU1hWEZIdmJYR2t6cEpQJTJiaCUyYldJSVJFTjBSd244TzJRNFV5RUs0OFJKZDdLSWJPeXVUMXFNWVNwa0Y3bmlBak5kZmslM2Q=";
//string subscriptionUri = "https://hk2.notify.windows.com/?token=AwYAAACKB3Noan4l%2bojXM5%2f3TDodPTegXbZxtTAzRktj3eWFOYmjjN1FPIdkuduXrwYZByFKLxy1gXy8rCmf1FSM6GH92rva7ecbQ%2b1%2bnGYxLWxoAI0GL03fZbV29p%2fu%2fJYrHQI%3d";
//string subscriptionUri = "http://sn1.notify.live.net/throttledthirdparty/01.00/aHR0cHM6Ly9zaW4ubm90aWZ5LndpbmRvd3MuY29tLz90b2tlbj1Bd1lBQUFEckVzRmdhR2phMXQ1aVo5MGdvRzAzejR5cE1SJTJiMHIwR2ZQc0Q0U0xzYnJOY2V3JTJmdU5pek1kZER4ZG9UdE5CM05PbjQ4dU9yUktzakN0U2JJa2lObmdBQVljQzdScDZ0blRBZlBDWjB4OWlZMDJRSDF3JTJieHM1ZzVMSTlWSXdGZWslM2Q=";
// string subscriptionUri = "https://sin.notify.windows.com/?token=AwYAAADrEsFgaGja1t5iZ90goG03z4ypMR%2b0r0GfPsD4SLsbrNcew%2fuNizMddDxdoTtNB3NOn48uOrRKsjCtSbIkiNngAAYcC7Rp6tnTAfPCZ0x9iY02QH1w%2bxs5g5LI9VIwFek%3d";
var sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);
// Create an HTTPWebRequest that posts the toast notification to the Microsoft Push Notification Service.
// HTTP POST is the only method allowed to send the notification.
sendNotificationRequest.Method = "POST";
// The optional custom header X-MessageID uniquely identifies a notification message.
// If it is present, the same value is returned in the notification response. It must be a string that contains a UUID.
// sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>");
// Create the toast message.
var toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>" + message + "</wp:Text1>" +
"</wp:Toast> " +
"</wp:Notification>";
// Set the notification payload to send.
byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);
// Set the web request content length.
sendNotificationRequest.ContentLength = notificationMessage.Length;
sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
sendNotificationRequest.Headers.Add("X-NotificationClass", "2");
using (var requestStream = sendNotificationRequest.GetRequestStream())
{
requestStream.Write(notificationMessage, 0, notificationMessage.Length);
}
// Send the notification and get the response.
var response = (HttpWebResponse)sendNotificationRequest.GetResponse();
var notificationStatus = response.Headers["X-NotificationStatus"];
var notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
var deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
// Display the response from the Microsoft Push Notification Service.
// Normally, error handling code would be here. In the real world, because data connections are not always available,
// notifications may need to be throttled back if the device cannot be reached.
var rep = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
return rep;
}
catch (Exception ex)
{
return ex.ToString();
// TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
}
this is my service I am sending on uri to this service,but I don't know whenever came to response it will throw exeception"The remote server returned an error: (400) Bad Request."but i dont know what type of uri will give.in this uri with send one key but which type of key will send please anyone reply me
You could check out PushSharp It appears to have been updated for the new notification payload formats in Windows Phone 8. Here is the server code for sending Push Notifications from a Server and in this link you can find the implementation for the Windows Phone.
Basically, there are two types of Push notification your app may be using in Windows Phone 8.1.
MPNS: Microsoft Push Notification Service
WNS: Windows Notification Service.
MPNS is the old style notification service used in Windows Phone 7 and 8. WNS is the Windows 8 style notification which is available to Applications specifically targeting Windows Phone 8.1. (Windows Phone Silverlight 8.1 apps and Windows Phone 8.1 (Windows runtime) apps.
PushSharp appears to support both types of notification services, MPNS in the PushSharp.WindowsPhone libraries and WNS in the PushSharp.Windows libraries.
Also it might be worth checking out Azure for the same.
Here is a tutorial for the same => Send push notifications to authenticated users
Below are the steps needed for push notification for windows phone .
Your app requests a push notification URI from the Push client service.
The Push client service negotiates with the Microsoft Push Notification Service (MPNS), and MPNS returns a notification URI to the Push client service.
The Push client service returns the notification URI to your app.
Your app can then send the notification URI to your cloud service.
When your cloud service has info to send to your app, it uses the notification URI to send a push notification to MPNS.
MPNS routes the push notification to your app.
See this MSDN page to understand push notification in detail.
I tried to send notification manually with the following code:
void SendToastMessage(string pushUri, string message)
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(pushUri);
request.ContentType = "text/xml";
request.Method = "POST";
request.Headers.Add("X-MessageID", Guid.NewGuid().ToString());
request.Headers.Add("X-NotificationClass", "2");
request.Headers.Add("X-WindowsPhone-Target", "toast");
string toastMessage = #"<?xml version=""1.0"" encoding=""utf-8""?>
<wp:Notification
xmlns:wp=""WPNotification"">
<wp:Toast>
<wp:Text1>{0}</wp:Text1>
<wp:Text2>{1}</wp:Text2>
</wp:Toast>
</wp:Notification>";
string toastXml = string.Format(toastMessage,
"sample:",
message);
byte[] notificationMessage = Encoding.UTF8.GetBytes(toastXml);
request.ContentLength = notificationMessage.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(notificationMessage,
0,
notificationMessage.Length);
}
try
{
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();
return;
}
catch (Exception ex)
{
return;
}
}
This code worked perfectly fine to me a year earlier and it still does. But make sure your pushUri is correct.
I am trying to implement like this http://dotnettrain.blogspot.co.uk/2011/07/push-notifications-in-windows-phone-75.html
I am sending and receiving in the same page. A.xaml
The Payload I am trying to send :In GetToastPayLoad
string message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>New Link Request</wp:Text1>" +
"<wp:Text2>"+data.Title+"</wp:Text2>" +
"</wp:Toast>" +
"</wp:Notification>";
And the header for httpRequest is :-
.........................................
var request = (HttpWebRequest)WebRequest.Create(new Uri(channelUri));
request.Method = "POST";
request.ContentType = "text/xml";
payload = GetToastPayload(data);
request.Headers.Add("X-WindowsPhone-Target", "toast");
request.Headers.Add("X-NotificationClass", "2");
}
I am able to capture the response in A.xaml as OnToastNotificationReceived and print in the details in a message box.
But when I remove the event handler, I am not getting any notification in my running application.
How can I receive and display in proper manner as a normal toast notification?
*What should I do to make this universal, say I want it to be displayed wherever the user is: A.xaml, B.xaml, C.xaml etc. ?*
To receive notifications anywhere try to put your code inside the App() constructor in App.xaml.cs as it is showed in Sending toast notifications on Windows Phone 7
Toast notifications are not showed when your app is running so you won't be able to show them this way (even if you try to manually execute ToastPrompt) So you should use ShellToastNotificationReceived to handle notifications in this case.
When your app is not running you should see toast notifications showed.