zoukankan      html  css  js  c++  java
  • WCF中的ServiceHost初始化两种方式

    1 代码方式 

    using(ServiceHost host=new ServiceHost(typeof(HelloWordService)))  
    {  
        host.AddServiceEndpoint(typeof(IHelloWordService),  
            new BasicHttpBinding(), new Uri("http://localhost:10000/HelloWorldService"));  
        host.AddServiceEndpoint(typeof(IHelloWordService),  
            new NetTcpBinding(), new Uri("net.tcp://localhost:10001/HelloWorldService"));  
      
        if (host.State != CommunicationState.Opening)  
            host.Open();  
    }  
    

    2 配置文件方式

    <services>
      <service behaviorConfiguration="serverBehavior" name="HelloWordService">
        <endpoint address="http://localhost:10000/HelloWorldService" 
                  binding="basicHttpBinding" contract="IHelloWordService"></endpoint>
        <endpoint address="net.tcp://localhost:10001/HelloWorldService" 
                  binding="netTcpBinding" contract="IHelloWorldService"></endpoint>
      </service>
    </services>

    当然也可以使用基地址的方式来配置

    <services>
      <service behaviorConfiguration="serverBehavior" name="HelloWordService">
        <endpoint address="HelloWorldService" 
                  binding="basicHttpBinding" contract="IHelloWordService"></endpoint>
        <endpoint address="HelloWorldService" 
                  binding="netTcpBinding" contract="IHelloWorldService"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:10000/"/>
            <add baseAddress="net.tcp://localhost:10001/"/>
          </baseAddresses>
        </host>
      </service>
    </services>

    配置好配置文件后就宿主程序中就很简单了,如下:

    using(ServiceHost host=new ServiceHost(typeof(HelloWordService)))
    {
        if (host.State != CommunicationState.Opening)
            host.Open();
    }

  • 相关阅读:
    对比Microsoft RemoteFX与VMware PCoIP
    SATA port selector and port muliplier 产品
    从并行 SCSI 到串行 SCSI
    转:快速远程桌面——Nomachine NX(ubuntu 10.10安装NX详解)
    全面分析:SATA2硬盘的发展和优缺点
    axel vpc
    转:网络带宽测量工具之iperf
    转:使用测试工具iPerf监控无线网络性能
    远程维护Helpdesk应用VNC
    QOS定义
  • 原文地址:https://www.cnblogs.com/jeffry/p/8665268.html
Copyright © 2011-2022 走看看