WCF入门-配置文件

上一篇关于wcf的文章是wcf入门实例

其中host一个服务是用代码配置的,这篇文章把host改成通过配置来启动服务。

配置文件内容

首先在配置文件中添加

 

 <system.serviceModel>
    <services>
      <service name="WCF.Service.CalculateService" >
        <endpoint 
          address="Cal"
          bindingConfiguration="http_Binding"
          binding="basicHttpBinding"
          contract="WCF.Contract.ICalculateService"/>

        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1:9876"/>
          </baseAddresses>
        </host>
          
       
      </service>
      
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="http_Binding"
                  sendTimeout="0:10:0"
                  receiveTimeout="0:10:0"
                  openTimeout="0:10:0"
                  closeTimeout="0:10:0"
                  transferMode="Streamed"
                 />
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

首先定义一个system.serviceModel节点,wcf的配置都是在这个节点下面。然后要定义服务。services下可以定义多个service,service下面有endpoint,每个endpoint包括abc的定义,每个service下面可以有多个endpoint。service下面的host配置了服务的基地址,可以通过endpoint的address来区分不同的endpoint的address和services同一个层次的bindings下面配置binding比如本例中用到的basicHttpBinding,下面有一个此类型binding的一个实例,通过name来标识这个实例。

重点释义

下面说一下几个timeout的含义

client端

sendtimeout:发送消息超时(向服务器发送一个请求,结果网络断了发布出去引起的超时),也包括在请求/应答模式下的接收消息超时(比如加法希望从服务器获得一个和,但是服务器运算需要很长时间导致client超时,请求应答模式简单讲就是需要服务器执行完给一个反馈,及时没有返回值)。

receivetimeout:客户端没有使用

opentimeout:建立连接发生超时

closetimeout:关闭连接发生超时

server端

sendtimeout opentimeout closetimeout与client意义一样

receivetimeout:指定一个会话闲置时间。比如对于实例模式为persession的服务,在建立一次连接的过程中是有一个session,如果没有断开连接并且长时间不与服务器进行通信,就会超时,这个就是receivetimeout

其他

对于上述所涉及到有

contract type:1.one—way 2.request/response 3.duplex

instance context mode:1.per-session 2.per-call 3.Single

transfermode:1.Streamed 2.Buffered 3.StreamedRequest 4.StreamedResponse

将在后续文章中一一解释

 

注:转载请注明出处 http://www.cnblogs.com/ITPuppy/archive/2013/04/17/3026518.html

posted on 2013-04-17 16:38  ITailor  阅读(1733)  评论(0)    收藏  举报

导航