Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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();


}

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900