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

    1 代码方式 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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();
    }
  • 相关阅读:
    dockerfile 详解
    kubectl简介
    关于高级事件的使用
    关于拖拽延伸出来的一些效果
    照片墙的制作过程及其出现的问题
    关于360度全景照片的问题总结
    实战演练-记账本App (五)
    人月神话阅读笔记02
    实战演练-记账本App(四)
    实战演练-记账本App(三)
  • 原文地址:https://www.cnblogs.com/WTFly/p/12252159.html
Copyright © 2011-2022 走看看