标签:winform style blog http color os io 使用 ar
一、理解面向服务(Service-Oriented-Architecture)
共享模式(schma)和契约
二、什么是WCF
1、统一性
2、互操作性
3、安全与可信赖
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace WcfService1 { // 注意: 如果更改此处的接口名称 "IService1",也必须更新 Web.config 中对 "IService1" 的引用。 [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // 任务: 在此处添加服务操作 [OperationContract] string HelloWorld(); } // 使用下面示例中说明的数据约定将复合类型添加到服务操作。 [DataContract] public class CompositeType { bool boolValue = true; string stringValue = "Hello "; [DataMember] public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] public string StringValue { get { return stringValue; } set { stringValue = value; } } } }
在winform中调用这个返回字符串
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace WcfService1 { // 注意: 如果更改此处的类名“Service1”,也必须更新 Web.config 和关联的 .svc 文件中对“Service1”的引用。 public class Service1 : IService1 { #region IService1 成员 string IService1.HelloWorld() { return "Hello WCF!"; } #endregion #region IService1 成员 public string GetData(int value) { throw new NotImplementedException(); } public CompositeType GetDataUsingDataContract(CompositeType composite) { throw new NotImplementedException(); } #endregion } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ServiceReference1.Service1Client client = new WindowsFormsApplication1.ServiceReference1.Service1Client(); MessageBox.Show(client.HelloWorld()); } } }
标签:winform style blog http color os io 使用 ar
原文地址:http://www.cnblogs.com/liuruitao/p/3964303.html