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
To achieve above task, follow the below steps. Assume, that Reader has a basic concept of
- WCF
- Silver Light
- Cross Domain Issue
- Hosting of WCF Service
Pictorial representation of output
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 {
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;
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>>
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:
Post a Comment