ServiceHost:配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--<system.ServiceModel> section -->
<system.ServiceModel>
<!-- services 节点中包含着所有Service的配置说明 -->
<services>
<!-- 第一个服务的配置开始都是一个<service ****>节点
相关属性解释:
name - 指定这个service配置是针对的哪一个WCF服务的(名称空间.类型名),ServiceHost载入一个服务后,会到配置文件中的<services>下找有没有name属性跟服务匹配的<service>的配置
behaviorConfiguration - 指定在<serviceBehaviors>下的一个<behavior>的name,这个特定<behavior>给这个service制定了一些行为,比如服务是否允许身份模拟
-->
<service name="NameSpace.ClassName" behaviorConfiguration="BehaviorName">
<!-- 每个服务可以有多个Endpoint,下面<endpoint>元素对每个Endpoint分别进行配置
属性说明:
address - 指定这个Endpoint对外的URI,这个URI可以是个绝对地址,也可以是个相对于baseAddress的相对地址。如果此属性为空,则这个Endpoint的地址就是baseAddress
binding - 指定这个Endpoint使用的binding,这个banding可以是系统预定义的9个binding之一,比如是basicHttpBinding,也可以是自定义的customBinding。binding决定了通讯的类型、
安全、如何编码、是否基于session、是否基于事务等等
contract - 指定这个Endpoint对应的Contract的全限定名(名称空间.类型名),这个Contract应该被service元素的name指定的那个service实现
bindingConfiguration - 指定一个binding的配置名称,跟<bindings>下面同类<binding>的name匹配
name - Endpoint的名称,可选属性,每个Contract都可以有多个Endpoint,但是每个Contract对应的多个Endpoint名必须是唯一的
-->
<endpoint address="URI" binding="basicHttpBinding" contract="Contract全限定名" bindingConfiguration="binding名" name="">
<!-- 用户定义的xml元素集合,一般用作SOAP的header内容-->
<headers>
<!-- 任何xml内容 -->
</headers>
<identity>
<!--<identity>下的元素都是可选的-->
<userPrincipalName></userPrincipalName>
<servicePrincipalName></servicePrincipalName>
<dns></dns>
<rsa></rsa>
<certificate encodedValue=""></certificate>
<!--<certificateReference>的属性都是可选的
属性说明:
storeName - 证书的存储区,可能值为:AddressBook,AuthRoot,CertificateAuthority ,My,Root,TrustedPeople,TrustedPublisher
storeLocation - 证书存储位置,可能值为:CurrentUser,LocalMachine-->
<certificateReference storeName="" storeLocation="">
</certificateReference>
</identity>
</endpoint>
<host>
<baseAddresses>
<!-- 在此可以定义每种传输协议的baseAddress,用于跟使用同样传输协议Endpoint定义的相对地
址组成完整的地址,但是每种传输协议只能定义一个baseAddress。HTTP的baseAddress同时是service
对外发布元数据的URL-->
<add baseAddress="http://address" />
</baseAddresses>
<timeouts></timeouts>
</host>
</service>
</services>
<!--绑定配置-->
<bindings>
<!-- 指定一个或多个系统预定义的binding,比如<basicHttpBinding>,当然也可以指定自定义的customBinding,
然后在某个指定的binding下建立一个或多个配置,以便被Endpoint来使用这些配置 -->
<basicHttpBinding>
<!-- 某一类的binding的下面可能有多个配置,binding元素的name属性标识某个binding-->
<binding name="binding名">
</binding>
</basicHttpBinding>
</bindings>
<!-- 定义service和Endpiont行为-->
<behaviors>
<!-- 定义service的行为-->
<serviceBehaviors>
<!-- 一个或多个系统提供的或定制的behavior元素
属性说明:
name - 一个behavior唯一标识,<service>元素的behaviorConfiguration属性指向这个name-->
<behavior name="">
<!-- 指定service元数据发布和相关信息
属性说明:
httpGetEnabled - bool类型的值,表示是否允许通过HTTP的get方法获取sevice的WSDL元数据
httpGetUrl - 如果httpGetEnabled为true,这个属性指示使用哪个URL地址发布服务的WSDL,
如果这个属性没有设置,则使用服务的HTTP类型的baseAddress后面加上?WSDL-->
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://URI:port/address" />
</behavior>
</serviceBehaviors>
<!-- 定义Endpiont的行为-->
<endpointBehaviors>
</endpointBehaviors>
</behaviors>
<!-- 包含客户端跟服务端连接使用到的Endpoint的配置 -->
<client>
<!-- 每个客户端Endpoint设置
属性说明:
address - ServiceHost的这个Endpoint的address
binding - 指定这个Endpoint使用的binding,这个binding可以是系统预定义的9个binding之一,
比如是basicHttpBinding
contract - 指定这个Endpoint对应的Contract的全限定名(名称空间.类型名)
name - Endpoint的名称,客户端代理类的构造方法中的endpointConfigurationName对应到这个name
bindingConfiguration - 指定客户端binding的具体设置,指向<bindings>元素下同类型binding的name -->
<!--如果此处有多个endpoint,系统会默认使用最后一个endpoint的配置-->
<endpoint address="URI" binding="basicHttpBinding" bindingConfiguration="binding名"contract="Contract全限定名" name="endpoint配置名" />
</client>
</system.ServiceModel>
</configuration>
ServiceClient:配置 (如果我们是在一个项目中添加了WCF引用时,系统会在app.config或者是web.config文件中添加一些相应的配置)
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICPWService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://xxx.xxx.com/wcf/Service.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
contract="Namespace.IService" name="endpointname" />
</client>
</system.serviceModel>