Как мне...выполнить этот фрагмент кода на языке Си#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SqlServer.Server; using System.Data.SqlTypes; using System.Net; using System.IO; namespace FCMSQL { public class BaseFunctionClass { public BaseFunctionClass() { } #region "Welcome Function" /// <summary> /// This function will be called from the SQL Stored Procedure. /// </summary> /// <param name=""strName"">Name</param> /// <returns>Welcome Message</returns> [SqlProcedure] public static void GetMessage(SqlString strName, out SqlString strMessge) { string serverKey = "AAAAYMU8LNo:APA91bHkuINssRFTKcW8Cc1r9i3ZsERgLtS8DQqnnZzXkLZ3Xwj2nL9LujhlecCyzl5a4vc_K7859DqLTv8Q0bUqfCYi4M7yifZPUgaE9ck4cLt2N73oWbfNr4G1psffc828rIYzVa4U"; var result = "-1"; var webAddr = "https://fcm.googleapis.com/fcm/send"; var regID = "dOw3Z_v6Gsg:APA91bGdmf_mkCmQsKWQH0vNCpfifawOeXOzKBqMxcFxhy4A88bo56qKE_-vGbTE_lAkcrWU1_5svhR3l6q6PqU0Sr6agJq0SVhmMxHe9MPPEpahGxHVeNdjX_xhma3VqQVZ6o2HqEAN"; var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + serverKey); httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"" + regID + "\",\"notification\": {\"title\": \"New deal\",\"body\": \"welcome \"},\"priority\":10}"; //registration_ids, array of strings - to, single recipient streamWriter.Write(json); streamWriter.Flush(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } strMessge = "Welcome," + strName + ", " + "your code is gettingexecuted under CLR !"; } #endregion } }
Что я уже пробовал:
Как преобразовать этот фрагмент кода в файл C# или просто рассказать, как запустить этот код на C#.
GKP1992
Какую ошибку вы получаете при попытке запустить его? Судя по всему, этот код уже находится в C#, так что вам не нужно конвертировать его в C#.
Richard MacCutchan
Это уже C#, поэтому вам просто нужно построить его с помощью Visual Studio, а затем выполнить его.