数据契约[DataContract] public class Employee { [DataMember] public int ID;
[DataMember] public string Name; }
操作契约 [ServiceContract] public interface IEmployeeService { [OperationContract] void AddEmployee(Employee emp);[OperationContract] string GetEmployeeNameByID(int id); }
服务与EndPoint绑定 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="HelloWorldWCF.EmployeeService" behaviorConfiguration="basicHttpBinding_EmployeeService"> <endpoint address="" binding="basicHttpBinding" contract="HelloWorldWCF.IEmployeeService"></endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="basicHttpBinding_EmployeeService"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 为什么叫做Hello world程序,因为客户通过点add service reference来添加服务,vs自动帮你生成服务端的代理类和配置文件,就像web service的调用一样简单吧。 示例下载 shore 2008-02-28 11:35 发表评论转载于:https://www.cnblogs.com/hotsoho.net/archive/2008/02/28/1206551.html