My first wcf, the first wcf

Source: Internet
Author: User

My first wcf, the first wcf

Create a new solution in vs2012

Create a WCF project RestApi

Add object class

   [DataContract]    public class Employee    {        private Guid id;        private string name;        private DateTime birthdate;        [DataMember]        public Guid Id        {            get { return id; }            set { id = value; }        }        [DataMember]        public string Name        {            get { return name; }            set { name = value; }        }        [DataMember]        public DateTime Birthdate        {            get { return birthdate; }            set { birthdate = value; }        }    }

Add Interface Class IServiceTest

1 // Note: You can use the "RENAME" command on the "refactoring" menu to change the Interface Name "IService1" in the Code and configuration file at the same time ". 2 [ServiceContract (Name = "ToSender", Namespace = "http://ToSender.com/webservices/")] 3 public interface ICostService 4 {5 [OperationContract] 6 Guid AddEmployee (Employee employee ); 7 8 [OperationContract] 9 void DeleteEmployee (string id); 10 11 12 [OperationContract] 13 Employee UpdateEmployee (Employee employee ); 14 15 16 [OperationContract] 17 Employee GetEmployee (string id); 18 19 CompositeType GetDataUsingDataContract (CompositeType composite); // TODO: add your service operation 20 here}View Code

Add the svc file CostService. svc

1 public class CostService: ICostService 2 {3 4 5 public Guid AddEmployee (Employee employee) 6 {7 8 return Guid. newGuid (); 9} 10 11 12 13 public void DeleteEmployee (string id) 14 {15 return; 16} 17 18 19 20 public Employee UpdateEmployee (Employee employee) 21 {22 return employee; 23} 24 25 26 27 public Employee GetEmployee (string id) 28 {29 return new Employee () {Id = Guid. newGuid (), Name = "Neil Klugman", Birthdate = new DateTime (1930, 1, 1) };30} 31 32 33 public CompositeType GetDataUsingDataContract (CompositeType composite) 34 {35 if (composite = null) 36 {37 throw new ArgumentNullException ("composite"); 38} 39 if (composite. boolValue) 40 {41 composite. stringValue + = "Suffix"; 42} 43 return composite; 44} 45}View Code

Web. config file configuration

1 <? Xml version = "1.0"?> 2 <configuration> 3 4 <system. web> 5 <compilation debug = "true" targetFramework = "4.0"/> 6 <authentication mode = "None"/> 7 So far, a complete wcf is completed. In vs2012, select the svc file and press F5 for debugging. wcfTestClicent and iis (for boarding the wcf Service) that comes with vs are automatically started)

 

Add a service on the wcf Client

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.