WCF中的配置

  • 我们也可以定义多个endpoint

    <services>
    <service
    name="Microsoft.ServiceModel.Samples.CalculatorService"
    behaviorConfiguration="CalculatorServiceBehavior">
    <endpoint address=""
    binding="wsHttpBinding"
    contract="Microsoft.ServiceModel.Samples.ICalculator" />
    <endpoint address="mex"
    binding="mexHttpBinding"
    contract=" Microsoft.ServiceModel.Samples.IMetadataExchange" />
    </service>
    </services>

    <host>
    <baseAddresses>
    <add baseAddress=
    "http://localhost/ServiceModelSamples/service.svc"/>
    </baseAddresses>
    </host>

 

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

当我们在定义一个实现了Service Contract的类时, binding和address信息是客户端必须知道的,否则无法调用该服务。然而,如果需要指定服务在执行方面的相关特性时,就必须定义服务的behavior。在WCF中,定义behavior就可以设置服务的运行时属性,甚至于通过自定义behavior插入一些自定义类型。例如通过指定ServiceMetadataBehavior,可以使WCF服务对外公布Metadata。

<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
<serviceBehaviors>
<behaviors>

posted @ 2012-03-15 21:15    阅读(315)  评论(0编辑  收藏  举报