• 笔记--Wcf全面解析(上)---(1)


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    using System.Text;
    using System.Threading.Tasks;
    using WcfServer2;
    
    namespace UnitTest
    {
        public class WCFBase
        {
            public WCFBase()
            {
                /*2.1,Address:通过URI做唯一标识、
                 *       URI类型:
                 *              ----HTTP/HTTPS
                 *              ----Net.TCP
                 *              ----Net.Pipe
                 *              ----Net.Msmq
                 */
    
    
                /*2.2,EndPointAddress
                 * 
                 * public class ServiceEndpoint
                  {
                 *  标识终结点地址
                    1,public EndpointAddress Address    {get;set;}
                 *                System.ServiceModel.EndpointAddress
                 *                {
                 *                    Uri(定位),Headers(辅助寻址),Identity(身份识别) 三个只读属性
                 *                }
                 *                  ServiceEndpoint通过  基类ServeiceHostBase中的
                 *                  AddServiceEndpoint方法增加终结点
                 */
                  //代码
                    using (System.ServiceModel.ServiceHost service = new ServiceHost(typeof(IDataTransferCallback)))
                    {
                        service.AddServiceEndpoint(typeof(IDataTransferCallback),  //实现契约的接口,只能以字符串和Type形式绑定
                                                    new WSHttpBinding(),                //绑定类型
                                                   "http://www.baidu.com");             //地址 可以是URI类型,也可以是String类型的地址
                        service.Open();
    
                        //service.Description.Endpoints 可以获取该服务的所有终结点信息
                    }
                //配置
                    //<system.serviceModel>表示wcf的配置节点
                    //    其中<services>包含了一组表示单个服务的<service>子节点
                    //        <service>节点中的Name属性表示服务的名称
                    //        还包含了一组<endpoint>,通过address,binding,contract做为终结点的3要素
    
                //ServiceHost构造函数
                        //前面参数serviceType 为服务类型,后面Uri表示可以访问到此服务的所有地址
                        //public ServiceHost(System.Type serviceType, params Uri[] baseAddresses);
                        //public ServiceHost(object singletonInstance, params Uri[] baseAddresses);
    
                 
    
    
                //  //1,客户端使用源数据生成接口
                //    class DataTransferCallbackClient : ClientBase<IDataTransferCallback>, IDataTransferCallback
                //    { 
    
                //        public void ReturnResult(string strJson)
                //        {
                //            base.Channel.ReturnResult(strJson);
               
                //        }
             
                //    }
                ////使用Channel生成
                //    //var factory = new ChannelFactory<IDataTransferCallback>();
                //    //var instance=factory.CreateChannel(new EndpointAddress("http://test.com/DataTransferCallback"));
                //    //instance.ReturnResult();
                 
    
                 /*              
                   2,public ContractDescription Contract{get;set;}
                 * 
                   3,public Binding Binding            {get;set;}
                  }
                 *
                 */
    
                /*客户端终结点*/
    
                
                //服务调用的本质:采用匹配的终结点对目标终结点调用
                
                p34
                
    
            }
        }
      
        
    }
  • 相关阅读:
    python之squid实现免费 IP代理 (windows win7 单机 本机 本地 正向代理 区分 HTTPS)
    python之PIL 二值图像处理和保存
    python之GIL release (I/O open(file) socket time.sleep)
    python之多线程 threading.Lock() 和 threading.RLock()
    python之GIL官方文档 global interpreter lock 全局解释器锁
    python多线程之t.setDaemon(True) 和 t.join()
    python之工作目录和文件引用
    python 代理
    原 浅谈移动端开发--物理像素和逻辑像素
    解决移动端页面在苹果端滑不到底部的问题
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3865038.html
Copyright © 2020-2023  润新知