I am currently using Visual Studio 2015 and is building a website. I have tried using OperationContracts and ServiceContracts with a 3-tier architecture, however, I could only do the basic things (Create, Retrieve, Update, Delete with normal strings/int).
I want to ask, for the Web Service WCF, is it possible to retrieve a PDF File from another database?
Here’s the scenario I’m working towards:
- Company A uses Web service (WCF) to retrieve Invoice data(All in different attributes e.g. InvoiceNum, PaymentAmt etc) from Supplier A.
- Company A uses external API to fill in all the fields into a template and download as a PDF file.
- Company A uses Web service (WCF) to insert the Invoice PDF into the Supplier A’s database and store as a PDF file.
- Company A stores the PDF as a type BLOB in their own database (SQL LocalDB).
Is the above scenario possible? If it’s possible, are there any guidelines/known links I can refer/try out to achieve the scenario?
Pdf could been seen as a file. You could use byte[] to transfer file. Below is my simple sample.
My contract.
My service. AspNetCompatibilityRequirementsMode.Allowed is used to enable HttpContext or it will be null. Here I directly save the file in the server, if you want to save it in sqlserver , just use varbinary field to save the byte[] of pdf file.
My web.config of wcf service. The bindingconfiguration ECMSBindingConfig is used to enable uploading large data or the service doesn't allow too large data. serviceHostingEnvironment's aspNetCompatibilityEnabled should also be set to true or HttpContext will be null.
My client. User webform as a sample.
Code behind. Here I use channelFacotory ,it is similar to client generated by visual studio
Web.config of client.
I assume the user uploads pdf, if you want to upload other files , you could add file extension as the service's parameter. Other operation should be similar.