• WCF-复杂配置


      两种模式,一个契约两个实现,两个契约一个实现。

    服务类库

    宿主

    static void Main(string[] args)
            {
                ServiceHost sh1 = new ServiceHost(typeof(WCFComplexLib.OneImpTowInt.People));
                sh1.Open();
                Console.WriteLine("一个实现两个接口服务开启");
                ServiceHost sh2 = new ServiceHost(typeof(WCFComplexLib.OneIntTowImp.Student));
                sh2.Open();
                Console.WriteLine("一个接口两个实现  学生服务开启");
                ServiceHost sh3 = new ServiceHost(typeof(WCFComplexLib.OneIntTowImp.Teacher));
                sh3.Open();
                Console.WriteLine("一个接口两个实现  老师服务开启");
                Console.ReadKey();
            }

    服务端配置文件

    <system.serviceModel>
        <services>
          <!--两个契约一个实现服务-->
          <service behaviorConfiguration="customBehavior" name="WCFComplexLib.OneImpTowInt.People">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:6001/"/>
              </baseAddresses>
            </host>
            <endpoint address="OneImpTowIntPeopleStudent" binding="basicHttpBinding" contract="WCFComplexLib.OneImpTowInt.IStudent"></endpoint>
            <endpoint address="OneImpTowIntPeopleTeacher" binding="basicHttpBinding" contract="WCFComplexLib.OneImpTowInt.ITeacher"></endpoint>
          </service>
          
          <!--两个实现一个契约  学生服务-->
          <service behaviorConfiguration="customBehavior" name="WCFComplexLib.OneIntTowImp.Student">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:6002/" />
              </baseAddresses>
            </host>
            <endpoint address="OneIntTowImpStudent" binding="basicHttpBinding" contract="WCFComplexLib.OneIntTowImp.IPeople"></endpoint>
          </service>
    
          <!--两个实现一个契约  老师服务-->
          <service behaviorConfiguration="customBehavior" name="WCFComplexLib.OneIntTowImp.Teacher">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:6003/" />
              </baseAddresses>
            </host>
            <endpoint address="OneIntTowImpTeacher" binding="basicHttpBinding" contract="WCFComplexLib.OneIntTowImp.IPeople"></endpoint>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="customBehavior">
              <serviceMetadata httpGetEnabled="True"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    客户端

            static void Main(string[] args)
            {
                OneImpTwoIntPeople.StudentClient oitnps = new OneImpTwoIntPeople.StudentClient();
                Console.WriteLine(oitnps.GetStudentName(1));
    
                OneImpTwoIntPeople.TeacherClient oitnpt = new OneImpTwoIntPeople.TeacherClient();
                Console.WriteLine(oitnpt.GetTeacherName(1));
    
                OneIntTowImpStudent.PeopleClient oitisp = new OneIntTowImpStudent.PeopleClient();
                Console.WriteLine(oitisp.GetPeopleName(1));
                OneIntTowImpTeacher.PeopleClient oititp = new OneIntTowImpTeacher.PeopleClient();
                Console.WriteLine(oititp.GetPeopleName(1));
    
                Console.ReadKey();
            }

    源码下载

  • 相关阅读:
    RAM调优之日志分析
    HDU Always Cook Mushroom (极角排序+树状数组)
    并非全部的程序猿都适合做技术管理
    HTTP Header具体解释
    Linux 通配符
    寻找正在连接中的网络连接
    hdu 1052 田忌赛马
    linux上电自启动应用程序具体解释
    C++ 中的 const 类型变量
    FileUtil
  • 原文地址:https://www.cnblogs.com/wudequn/p/7088948.html
Copyright © 2020-2023  润新知