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

  • 相关阅读:
    HDFS under replicated blocks
    docker-compose
    shell $* 和$@ 的区别以及运算操作
    ajax与文件上传
    Django之模型层(多表操作)
    Django之模型层(单表操作)
    Django之模板层
    Django之视图层
    Django之路由层
    Django之web应用、http协议和django简介
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1929267.html
Copyright © 2011-2022 走看看