[WebMethod(Description = "Google Messages")]
public string SendGoogleMessagesToDevice(string message, string googleAppId, string registrationId)
{
message = string.Concat(message);
//Debugger.Launch();
//SendNotification(message, googleAppId, registrationId);
System.Net.WebRequest tRequest;
// Take it form web.config
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
// plane text processing other than json
tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";//"application/json";//
tRequest.Headers.Add(HttpRequestHeader.Authorization, "key=" + googleAppId);
string postData = "data.message=" + message + "®istration_id=" + registrationId + "";
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
return sResponseFromServer;
}