Please download the basic skeleton of WCF Solution which I coded for you.
http://sdrv.ms/16Bkt2r[
^]
Don't get me wrong. First of all you need to understand the basics of WCF.
1. The Address , Binding, Contract.
2. How to Create and Consume Service
3. How to host the service.
You will have to code the service to receive Purchase Orders as Stream. Below is the Service Contract which you can go for.
[ServiceContract]
public interface IFileUploadService
{
[OperationContract]
UploadResponse Upload(UploadRequest uploadRequest);
}
Here's the UploadRequest Message Contract.
[MessageContract]
public class UploadRequest
{
[MessageBodyMember]
public Stream Stream { get; set; }
}
Here's the Response. For now it just returns the response with UploadSucceeded set to True. You will have to change it suitably
[MessageContract]
public class UploadResponse
{
[MessageBodyMember]
public bool UploadSucceeded { get; set; }
}
And finally here's the Service Implementation. Where you read the Stream Content using StreamReader. Get all the contents and hold in StringBuilder so that later you can save the same in database.
public class PurchaceOrderService : IFileUploadService
{
public UploadResponse Upload(UploadRequest uploadRequest)
{
var fileContentStringBuilder = new StringBuilder();
using (StreamReader sr = new StreamReader(uploadRequest.Stream))
{
string line;
while ((line = sr.ReadLine()) != null)
{
fileContentStringBuilder.AppendLine(line);
}
}
var purchaceOrder = fileContentStringBuilder.ToString();
return new UploadResponse
{
UploadSucceeded = true
};
}
}