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();
            }

    源码下载

  • 相关阅读:
    telnet发邮件
    怎样接收电子邮件(POP3协议简介)(转载,写的很简洁)
    总结:string,char*,CString,int,WCHAR*之间的相互转换:
    文件查找
    SOAP消息机制简介
    jQuery 万能的选择器 NO.1
    数据库通用操作类
    jQuery (三) 管理jQuery包装集
    WebService Learning
    使用JQuery读取XML文件数据
  • 原文地址:https://www.cnblogs.com/wudequn/p/7088948.html
Copyright © 2011-2022 走看看