WCF services配置节问题解析

开发 后端
WCF services配置节包含name和behaviorConfiguration属性,这里有详细的分析,希望通过读本文会有很大的提高。

在WCF的快速发展,它的性能也随之增长,但是有很多人都对配置文件很头疼,现在就教教大家吧。在WCF services配置节中可以定义多个服务,每一个服务都被放到service配置节中,WCF的宿主程序可以通过配置文件找到这些定义的服务并发布这些服务。WCF services配置节包含name和behaviorConfiguration属性。其中,name配置了实现ServiceContract的类型名。类型名必须是完整地包含了命名空间和类型名。

#T#而behaviorConfiguration的配置值则与其后的behaviors配置节的内容有关。endpoint是service配置节的主体,其中,endpoint配置节包含了endpoint的三个组成部分:Address、Binding和Contract。由于具体的binding配置是在bindings配置节中完成,因而,在endpoint中配置了bindingConfiguration属性,指向具体的binding配置。如下所示:

  1. services  
  2. servicename="BruceZhang.MyService"behaviorConfiguration="MyBehavior"  
  3. endpointaddress="" 
  4. binding="netTcpBinding" 
  5. bindingConfiguration="DuplexBinding" 
  6. contract="BruceZhang.IHello"/  
  7. /service  
  8. /services 

我们也可以定义多个endpoint,例如:

  1. services  
  2. service  
  3. name="Microsoft.ServiceModel.Samples.CalculatorService" 
  4. behaviorConfiguration="CalculatorServiceBehavior" 
  5. endpointaddress="" 
  6. binding="wsHttpBinding" 
  7. contract="Microsoft.ServiceModel.Samples.ICalculator"/  
  8. endpointaddress="mex" 
  9. binding="mexHttpBinding" 
  10. contract="Microsoft.ServiceModel.Samples.IMetadataExchange"/  
  11. /service  
  12. /services 

如果address值为空,那么endpoint的地址就是默认的基地址(BaseAddress)。例如ICalculator服务的地址就是http://localhost/servicemodelsamples/service.svc,而IMetadataExchange服务的地址则为http://localhost/servicemodelsamples/service.svc/mex。这里所谓的基地址可以在WCF services配置节中通过配置host来定义:

  1. service  
  2. name="Microsoft.ServiceModel.Samples.CalculatorService" 
  3. behaviorConfiguration="CalculatorServiceBehavior" 
  4. host  
  5. baseAddresses  
  6. addbaseAddress=  
  7. "http://localhost/ServiceModelSamples/service.svc"/  
  8. /baseAddresses  
  9. /host  
  10. endpoint…/  
  11. /service  
责任编辑:田树 来源: 博客
相关推荐

2010-02-22 17:29:47

WCF跨域

2009-11-05 15:50:25

WCF behavio

2009-12-08 17:08:13

WCF Service

2010-02-22 10:18:18

WCF配置文件

2009-11-06 15:47:17

WCF Windows

2009-12-21 11:19:50

WCF配置文件

2010-04-29 12:42:09

Unix系统

2012-07-24 17:10:10

Linux操作系统

2011-07-18 15:20:28

Core Services 框架

2010-02-23 17:49:56

WCF传输大数据

2010-02-24 10:55:01

WCF跨域访问

2009-07-20 14:04:27

WebWork标签嵌套

2012-05-23 13:11:10

架构存储

2010-01-28 13:15:43

C++参数

2009-07-16 17:26:11

WebWork文件上传

2010-11-23 15:50:44

MySQL中文建表

2010-02-23 17:57:58

Python部署

2009-12-21 18:39:24

WCF字符串过长问题

2009-11-05 13:08:44

WCF客户端配置

2009-12-22 11:21:43

WCF跨域访问
点赞
收藏

51CTO技术栈公众号