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标签

  • 相关阅读:
    bzoj1096: [ZJOI2007]仓库建设
    bzoj3289: Mato的文件管理
    bzoj1878: [SDOI2009]HH的项链
    bzoj1295: [SCOI2009]最长距离
    bzoj1056: [HAOI2008]排名系统 && 1862: [Zjoi2006]GameZ游戏排名系统
    vijosP1026毒药?解药?
    bzoj1293: [SCOI2009]生日礼物
    bzoj1483: [HNOI2009]梦幻布丁
    PCB开窗
    3W原则
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1929267.html
Copyright © 2011-2022 走看看