hi
i am new in wcf restful and i want to upload xml file to server from client end for this i create wcf service but question is how to used it on client end like asp.net page so that client can upload file easily to server.
What I have tried:
my wcf service implementation code below
thanks in advance
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
void FileUpload(RemoteFileInfo request);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "UploadFile")]
void UploadFile(string fileName, Stream fileStream);
}
[MessageContract]
public class RemoteFileInfo : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]
public long Length;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream;
public void Dispose()
{
if (FileByteStream != null)
{
FileByteStream.Close();
FileByteStream = null;
}
and this is implementation class code
public class RestServiceImpl : IRestServiceImpl
{
public void UploadFile(string filename, Stream filestream)
{
FileStream filetoupload = new FileStream("D:\\FileUpload\\" + filestream, FileMode.Create);
byte[] bytearray = new byte[10000];
int byteread, totalByteRead = 0;
do
{
byteread = filestream.Read(bytearray, 0, bytearray.Length);
totalByteRead += byteread;
}
while (byteread > 0);
filetoupload.Write(bytearray, 0, bytearray.Length);
filetoupload.Close();
filetoupload.Dispose();
}
}