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;
            }
        }
    }
  • 相关阅读:
    多态小结
    Lambda小结
    网络编程小结
    内部类与Lambda
    线程小结
    关于java的静态绑定与动态绑定小结
    多线程
    英语语法十二(可数名词不规则变化)
    英语语法入门十四(名词的作用)
    英语语法入门十三(不可数名词)
  • 原文地址:https://www.cnblogs.com/hongmaju/p/4272961.html
Copyright © 2011-2022 走看看