zoukankan      html  css  js  c++  java
  • 笔记--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
                
    
            }
        }
      
        
    }
  • 相关阅读:
    BZOJ1877: [SDOI2009]晨跑
    SPFA的两个优化:SLF与LLL
    BZOJ1858: [Scoi2010]序列操作
    java线程基础巩固---如何捕获线程运行期间的异常
    java线程基础巩固---如何给你的应用程序注入钩子程序
    类的命名空间与卸载详解及jvisualvm使用
    okhttp拦截器之RetryAndFollowUpInterceptor&BridgeInterceptor分析
    okhttp初识拦截器
    类加载器双亲委托机制实例深度剖析
    类加载器重要方法详解
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3865038.html
Copyright © 2011-2022 走看看