化零为整WCF(2) - 契约Contract(ServiceContract、OperationContract、DataContract、ServiceKnownType和DataMember)
2007-12-17 11:33
856 查看
[索引页]
[源码下载]
[align=center]化零为整WCF(2) - 契约Contract(ServiceContract、OperationContract、DataContract、ServiceKnownType和DataMember)[/align]
作者:webabcd
介绍
WCF(Windows Communication Foundation) - 契约(Contract):服务契约(ServiceContract),操作契约(OperationContract),数据契约(DataContract),服务已知类型(ServiceKnownType),数据成员(DataMember)。
示例
1、服务
IPersonManager.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
2、宿主
PersonManager.svc
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ContractBehavior">
<!--httpGetEnabled - 使用get方式提供服务-->
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!--name - 提供服务的类名-->
<!--behaviorConfiguration - 指定相关的行为配置-->
<service name="WCF.ServiceLib.Contract.PersonManager" behaviorConfiguration="ContractBehavior">
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="" binding="basicHttpBinding" contract="ConfigurationNameTest" />
</service>
</services>
</system.serviceModel>
</configuration>
3、客户端
PersonManager.aspx
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:TextBox ID="txtName" runat="server" Text="webabcd" />
<asp:Button ID="btnGetName" runat="server" Text="GetName"
onclick="btnGetName_Click" />
</asp:Content>
PersonManager.aspx.cs
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 Contract_PersonManager : System.Web.UI.Page
Web.config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="http://localhost:3502/ServiceHost/Contract/PersonManager.svc" binding="basicHttpBinding" contract="Contract.IPersonManager" />
</client>
</system.serviceModel>
</configuration>
运行结果:
单击"btnGetName"后弹出提示框,显示"Name: webabcd"
OK
[源码下载]
[源码下载]
[align=center]化零为整WCF(2) - 契约Contract(ServiceContract、OperationContract、DataContract、ServiceKnownType和DataMember)[/align]
作者:webabcd
介绍
WCF(Windows Communication Foundation) - 契约(Contract):服务契约(ServiceContract),操作契约(OperationContract),数据契约(DataContract),服务已知类型(ServiceKnownType),数据成员(DataMember)。
示例
1、服务
IPersonManager.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace WCF.ServiceLib.Contract
2、宿主
PersonManager.svc
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ContractBehavior">
<!--httpGetEnabled - 使用get方式提供服务-->
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!--name - 提供服务的类名-->
<!--behaviorConfiguration - 指定相关的行为配置-->
<service name="WCF.ServiceLib.Contract.PersonManager" behaviorConfiguration="ContractBehavior">
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="" binding="basicHttpBinding" contract="ConfigurationNameTest" />
</service>
</services>
</system.serviceModel>
</configuration>
3、客户端
PersonManager.aspx
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:TextBox ID="txtName" runat="server" Text="webabcd" />
<asp:Button ID="btnGetName" runat="server" Text="GetName"
onclick="btnGetName_Click" />
</asp:Content>
PersonManager.aspx.cs
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 Contract_PersonManager : System.Web.UI.Page
Web.config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="http://localhost:3502/ServiceHost/Contract/PersonManager.svc" binding="basicHttpBinding" contract="Contract.IPersonManager" />
</client>
</system.serviceModel>
</configuration>
运行结果:
单击"btnGetName"后弹出提示框,显示"Name: webabcd"
OK
[源码下载]
相关文章推荐
- 化零为整WCF(2) - 契约Contract(ServiceContract、OperationContract、DataContract、ServiceKnownType和DataMember)
- 化零为整WCF(2) - 契约Contract(ServiceContract、OperationContract、DataContract
- WCF Data Contract之KnownType
- 再说WCF Data Contract KnownTypeAttribute
- WCF Data Contract之KnownType
- DataContract KnownType---Data Transfer in Service Contracts
- WCF Data Contract之KnownType(转)
- 契约Contract(ServiceContract、OperationContract、DataContract、ServiceKnownType和DataMember)
- WCF 动态实现数据契约 ServiceKnownType
- WCF Data Contract之KnownType
- 再说WCF Data Contract KnownTypeAttribute
- 再说WCF Data Contract KnownTypeAttribute
- WCF Data Contract之KnownType
- WCF之 Contract之KnownType契约类型介绍
- WCF Data Contract KnownTypeAttribute---转载
- WCF --KnowType,ServiceKnownType,配置文件添加
- [原创]WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)
- WCF中ServiceContract,DataContract与MessageContract对比
- WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)
- WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)