zoukankan      html  css  js  c++  java
  • WCF默认实例的解读

    一:图片

    IService1.cs是定义的接口,包含对Service、方法和方法用的类的声明的声明

    Service1.cs是对接口的实现,包含实现的方法

    代码注释:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace WcfServiceLibraryTest
    {
        // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。
        [ServiceContract]
        public interface IService1//定义一个接口
        {
            [OperationContract]
            string GetData(int value);//定义一个方法,返回类型为string,参数为int
    
            [OperationContract]
            CompositeType GetDataUsingDataContract(CompositeType composite);//定义一个方法,返回类型为CompositeType,参数为CompositeType,下面为对象的定义
    
            // TODO: 在此添加您的服务操作
        }
    
        // 使用下面示例中说明的数据协定将复合类型添加到服务操作
        [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; }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace WcfServiceLibraryTest
    {
        // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“Service1”。
        public class Service1 : IService1//实现接口的类
        {
            public string GetData(int value)//实现的方法
            {
                return string.Format("You entered: {0}", value);
            }
    
            public CompositeType GetDataUsingDataContract(CompositeType composite)
            {
                if (composite == null)
                {
                    throw new ArgumentNullException("composite");
                }
                if (composite.BoolValue)
                {
                    composite.StringValue += "Suffix";
                }
                return composite;
            }
        }
    }
  • 相关阅读:
    虚拟机的Linux 安装 若干问题(一)
    理解JavaScript的闭包
    javascript里面的引用类型和值类型
    javascript导入自定义模块
    简单了解下CAP定理与BASE定理
    背包问题之完全背包
    背包问题之多重背包
    背包问题之0-1背包
    搜索算法初步总结
    谈一谈“回溯法“
  • 原文地址:https://www.cnblogs.com/hongmaju/p/4272961.html
Copyright © 2011-2022 走看看