WCF services配置節(jié)問題解析
在WCF的快速發(fā)展,它的性能也隨之增長,但是有很多人都對配置文件很頭疼,現在就教教大家吧。在WCF services配置節(jié)中可以定義多個服務,每一個服務都被放到service配置節(jié)中,WCF的宿主程序可以通過配置文件找到這些定義的服務并發(fā)布這些服務。WCF services配置節(jié)包含name和behaviorConfiguration屬性。其中,name配置了實現ServiceContract的類型名。類型名必須是完整地包含了命名空間和類型名。
#T#而behaviorConfiguration的配置值則與其后的behaviors配置節(jié)的內容有關。endpoint是service配置節(jié)的主體,其中,endpoint配置節(jié)包含了endpoint的三個組成部分:Address、Binding和Contract。由于具體的binding配置是在bindings配置節(jié)中完成,因而,在endpoint中配置了bindingConfiguration屬性,指向具體的binding配置。如下所示:
- services
- servicename="BruceZhang.MyService"behaviorConfiguration="MyBehavior"
- endpointaddress=""
- binding="netTcpBinding"
- bindingConfiguration="DuplexBinding"
- contract="BruceZhang.IHello"/
- /service
- /services
我們也可以定義多個endpoint,例如:
- services
- service
- name="Microsoft.ServiceModel.Samples.CalculatorService"
- behaviorConfiguration="CalculatorServiceBehavior"
- endpointaddress=""
- binding="wsHttpBinding"
- contract="Microsoft.ServiceModel.Samples.ICalculator"/
- endpointaddress="mex"
- binding="mexHttpBinding"
- contract="Microsoft.ServiceModel.Samples.IMetadataExchange"/
- /service
- /services
如果address值為空,那么endpoint的地址就是默認的基地址(BaseAddress)。例如ICalculator服務的地址就是http://localhost/servicemodelsamples/service.svc,而IMetadataExchange服務的地址則為http://localhost/servicemodelsamples/service.svc/mex。這里所謂的基地址可以在WCF services配置節(jié)中通過配置host來定義:
- service
- name="Microsoft.ServiceModel.Samples.CalculatorService"
- behaviorConfiguration="CalculatorServiceBehavior"
- host
- baseAddresses
- addbaseAddress=
- "http://localhost/ServiceModelSamples/service.svc"/
- /baseAddresses
- /host
- endpoint…/
- /service