File Uplalod from Silver Light application to server location using WCF

0 comments
This article will explain, How to upload a file from SilverLight client to server location using WCF.
To achieve above task, follow the below steps. Assume, that Reader has a basic concept of


  1. WCF
  2. Silver Light
  3. Cross Domain Issue
  4. Hosting of WCF Service
Pictorial representation of output

image1.gif

image2.gif

image3.gif

Follow the Steps below


Step 1:

Create and Host the WCF Service.

a. Create the Contract. This got only one method, which is taking as input a file to upload.

IService1.svc

using
System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
 namespace FileUploadService      
{
        [ServiceContract]
    public interface IService1                         {
 
        [OperationContract]
        void SaveFile(UploadFile UploadFile);
}
}

b. Create the Data Contract. This is going to contain the information about the uploaded file. You could either put this UploadFile Data Contract in same file with contract or in separate file.

[DataContract]
    public class UploadFile    {
        [DataMember]
        public string FileName;
        [DataMember]
        public byte[] File;
    }

c. Implement the Service. We are simply creating instance of FileStream in create mode and writing the stream into that.

READ MORE>>

0 comments: