zoukankan      html  css  js  c++  java
  • 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();
            }

    源码下载

  • 相关阅读:
    1348:【例4-9】城市公交网建设问题
    1392:繁忙的都市(city)
    1381:城市路(Dijkstra)
    初识微积分
    进阶数论(1)逆元
    [题解] Codeforces Round #549 (Div. 2) B. Nirvana
    简单数论之整除&质因数分解&唯一分解定理
    [题解]ybt1365:FBI树(fbi)
    [题解]一本通1240:查找最接近的元素
    [题解]NOIP2018(普及组)T1标题统计(title)
  • 原文地址:https://www.cnblogs.com/wudequn/p/7088948.html
Copyright © 2011-2022 走看看