Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Help.......................
I am new to WCF Services and have been assigned a project, where customer will send us orders through WCF. I have created a test service that accepts a site number and returns all the details of site name, address, telephone, fax, manager, city, state, zip etc. Now I need to create a service where client will send order(s), service will be attached to Website through IIS and will just listen for incoming requests. Any help at all will be greatly appreciated...

David
Posted
Comments
Ranjan.D 4-Nov-13 16:17pm    
Learning WCF by Michele Leroux Bustamante is a great book for beginners.

You said "Now I need to create a service where client will send order(s)" , Please explain do you need to process client orders ? To Receive Orders, You need to have a DataContract.
djc1160 4-Nov-13 17:20pm    
Yes need to receive Order(s), could you please give an example of how the DataContract will look, I am new to wcf and trying to learn as I build this service. How will I determine that service is receiving a file?
Ranjan.D 4-Nov-13 17:31pm    
Sorry I can't guide you with some random DataContract. Have a look into the book I suggested or download some code samples to learn how it works. You need to design or ask whether you will receive file as Streams. It depends on the requirements , We can't really assume things.
djc1160 4-Nov-13 17:50pm    
First of all thanks for your patience, I am trying to build a service that will receive the following data from our customer(s) this service will receive above file and add to database then respond with a "Received Order"




<xyzorders>
<orders>
<locationid>100
<TradingPartnerId>ServiceKing</TradingPartnerId>
<fcname>SK100 - 99th
<fcaddress>901 N. 99th Ave
<fccity>Tolleson
<fcstate>AZ
<fczip>85353
<PartnerCustomerNumber>5020290</PartnerCustomerNumber>
<PurchaseOrderNumber>OR158437</PurchaseOrderNumber>
<originalorderdate>13/08/2013 02:43 PM
<itemlist>
<item>
<LineNumber>673082</LineNumber>
<PartnersProductId>08881</PartnersProductId>
<xyzproductdescription>Undercoating, 08881, 16 oz Net Wt/453 g
<quantity>1

<item>
<LineNumber>673083</LineNumber>
<PartnersProductId>PEC4240</PartnersProductId>
<xyzproductdescription>Duramix Plastic Repair Semi-Rigid
<quantity>1

<item>
<LineNumber>673084</LineNumber>
<PartnersProductId>PEC4247</PartnersProductId>
<xyzproductdescription>Duramix Super Fast Repair Adhesive
<quantity>1




1 solution

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.

SQL
[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

C#
[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.

C#
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();
           
           // TOTO: Save the Purchace Order to Database.

           // Return the Response.
           
           return new UploadResponse
                    {
                        UploadSucceeded = true
                    };
       }
   }
 
Share this answer
 

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