Showing posts with label WCF Service. Show all posts
Showing posts with label WCF Service. Show all posts

Friday, February 10, 2017

To send push notification's to IOS device

To send push notifications to the IOS devices from WCF service we need to first install the push sharp  and the Newtonsoft.Json library from the NuGet package manager

To install the push sharp from package manager console type the following command 
Install-Package PushSharp
https://www.nuget.org/packages/PushSharp/
To install the Newtonsoft.Json from package manager console type the following command
 Install-Package Newtonsoft.Json
https://www.nuget.org/packages/Newtonsoft.Json/9.0.2-beta2 

After installing the package write the following code to send the notifications.



using Newtonsoft.Json.Linq;
using PushSharp.Apple;

  public void IosPushNotifications()
        {
            var certificate = File.ReadAllBytes("Add your certificate location");
            var configuration = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, certificate, "your certificate password");

            var ServiceBroker = new ApnsServiceBroker(configuration);

            string message = "Your message";
            ServiceBroker.Start();
            ServiceBroker.QueueNotification(new ApnsNotification
            {
                DeviceToken = "18545dd4eredf47834e4er4exxxxxxxxxxxxxxxxxxxxxxxxx",//your device token
                Payload = JObject.Parse("{'aps':{'badge':1,'sound':'oven.caf','alert':'" + message + "'}}")
            });

            ServiceBroker.Stop();
        }

Wednesday, January 25, 2017

Upload File In WCF REST Api Using Stream Data


I got the solution to upload the files but the problem was with the image files when i try to upload the doc,xls,ppt,txt etc files they were uploading and opening properly but when i try to upload any image file the file was getting uploaded but not opening. Then i did a lot of googling , search tech forums then finally i got the one more solution for that problem now you can upload files like docx,ppt,xls,txt,jpeg,png etc.
 
In  interface


[OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "UploadFile/{fileName}")]
    string UploadFile(string fileName,Stream streamData);

  
 In class

 
MultipartParser parser = new MultipartParser(streamData);

                if (parser.Success)
                {
                    string fileName = parser.Filename;
                    string contentType = parser.ContentType;
                    byte[] fileContent = parser.FileContents;
                    FileStream fileToupload = new FileStream("Path Name", FileMode.Create);
                    fileToupload.Write(fileContent, 0, fileContent.Length);
                    fileToupload.Close();
                    fileToupload.Dispose();
                    streamData.Close();
                }

For using the multipartparser class file you need to download it from the below link


In Web.Config file

<bindings>
      <webHttpBinding>
        <binding name="WebConfiguration"
                 maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647"
                 closeTimeout="00:01:00" openTimeout="00:01:00"
                 receiveTimeout="00:10:00" sendTimeout="00:01:00"
                 transferMode="Streamed">
         
        </binding>
      </webHttpBinding>
    </bindings>



 

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...