zoukankan      html  css  js  c++  java
  • wcf asp.net

    WCF服务
    App_Code/Customer.cs

    C# code
    using System.Runtime.Serialization; using System.ServiceModel; //实体类 [DataContract] public class Customer { [DataMember] public string FirstName; [DataMember] public string LastName; }


    IWCF_WithDataContract.cs

    C# code
    using System.Runtime.Serialization; using System.ServiceModel; [ServiceContract] public interface IWCF_WithDataContract { [OperationContract] string HelloFirstName(Customer cust); [OperationContract] string HelloFullName(Customer cust); }
    C# code
    using System.Runtime.Serialization; using System.ServiceModel; public class WCF_WithDataContract : IWCF_WithDataContract { public string HelloFirstName(Customer cust) { return "Hello" + cust.FirstName; } public string HelloFullName(Customer cust) { return "Hello" + cust.FirstName + " " + cust.LastName; } }


    客户端asp.net代码

    C# code
    using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class WithDataContractServiceTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnWithData_Click(object sender, EventArgs e) { WithDataContractService.WCF_WithDataContractClient ws = new WithDataContractService.WCF_WithDataContractClient(); WithDataContractService.Customer c = new WithDataContractService.Customer(); c.FirstName = "zhong"; c.LastName = "wei"; ws.HelloFullName(c); ws.Close(); } }


    引用的实体要加DataContract标签和DataMember标签

  • 相关阅读:
    软件需求阅读笔记02
    软件需求阅读笔记01
    搜狗输入法
    冲刺周之后感想
    典型用户分析和场景
    四则运算
    学习总结
    2019年春阅读笔记5——对开源的认知
    2019年春阅读笔记4——分布式消息系统的现状、挑战与未来
    2019年春阅读笔记3——数据库集群方案
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1929267.html
Copyright © 2011-2022 走看看