WCF 配置文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.ServiceModel> <!-- services 元素包含应用中驻留的所有service的 配置要求 --> <services> <!-- 每个服务的配置属性说明: name - 指 定这个service配置是针对的那个服务,为 一个实现了某些Contract的服务类的完全 限定名(名称空间.类型名),ServiceHost载入一个服务后,会 到配置文件中的 下找有 没有name属性跟服务匹配的 的配置 behaviorConfiguration - 指定在下的一个的name,这个特定给这个service制定了一些行为, 比 如服务是否允许身份模拟--> <service name="名称空间.类型名" behaviorConfiguration="behavior名"> <host> <baseAddresses> <!-- 在此可以定义每种传输协议的baseAddress, 用于跟使用同样传输协议Endpoint定义的相对地 址组成完整的地址,但是每种传输协议只能定义一个baseAddress。HTTP的baseAddress同时是service 对外发布服务说明页面的URL--> <add baseAddress="http://address" /> </baseAddresses> <timeouts></timeouts> </host> <!-- 每个服务可以有多个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的配置名称,跟下面同 类的name匹配 behaviorConfiguration - 指 定这个endpoint的behavior, 指向 下的同样配置名称的 name - Endpoint的名称,可选属性,每个Contract都可以有多个Endpoint,但是每个Contract对应的 多个Endpoint名必须是唯一的--> <endpoint address="URI" binding="basicHttpBinding" contract="Contract全限定名" bindingConfiguration="binding名" behaviorConfiguration="String" name=""> <!-- 用户定义的xml元素集合, 一般用作SOAP的header内容--> <headers> <!-- 任何xml内容 --> </headers> </endpoint> </service> </services> <bindings> <!-- 指定一个或多个系统预定义的binding, 比如,当然也可以指定自定义的customBinding, 然后在某个指定的binding下建立一个或多个配置,以便被Endpoint来 使用这些配置 --> <basicHttpBinding> <!-- 某一类的binding的下 面可能有多个配置,binding元素的name属 性标识某个binding--> <binding name="binding名"> </binding> </basicHttpBinding> </bindings> <!-- 定义service和Endpiont行为--> <behaviors> <!-- 定义service的行为--> <serviceBehaviors> <!-- 一个或多个系统提供的或定制的behavior元 素 属性说明: name - 一个behavior唯一标识,元素下的behaviorConfiguration属 性指向这个name--> <behavior name="此Behavior名称"> <!-- 指定service元数据发 布和相关信息 属性说明: httpGetEnabled - bool类型的值,表示是否允许通过HTTP的get方 法获取sevice的WSDL元数据 httpGetUrl - 如 果httpGetEnabled为true, 这个属性指示使用哪个URL地址发布服务的WSDL, 如果这个属性没有设置,则使用服务的HTTP类型的baseAddress后面加上?WSDL--> <serviceMetadata httpGetEnabled="true" httpGetUrl="http://URI:port/address" /> <!--指定验证服务端的凭据--> <serviceCredentials> <!--指定服务端的证书 属性说明: storeName - 证 书的存储区,可能值为:AddressBook,AuthRoot,CertificateAuthority Disallowed,My,Root,TrustedPeople,TrustedPublisher storeLocation - 证书存储位置,可能值为:CurrentUser,LocalMachine x509FindType - 查找证书的方式,可能的值:FindBySubjectName,FindByThumbPrint,FindByIssuerName...... findValue - 对应查找方式的要查找证书的值 --> <serviceCertificate storeName="存储区" storeLocation="存储位置" x509FindType="FindBySubjectName" findValue="server1" /> </serviceCredentials> </behavior> </serviceBehaviors> <!-- 定义Endpiont的行为--> <endpointBehaviors> <!-- 一个或多个系统提供的或定制的behavior元 素 属性说明: name - 一个behavior唯一标识,元素下的behaviorConfiguration属 性指向这个name--> <behavior name="此Behavior名称"> <!--指定客户端的凭据--> <clientCredentials> <!--指定客户端的证书 属性说明: storeName - 证 书的存储区,可能值为:AddressBook,AuthRoot,CertificateAuthority Disallowed,My,Root,TrustedPeople,TrustedPublisher storeLocation - 证书存储位置,可能值为:CurrentUser,LocalMachine x509FindType - 查找证书的方式,可能的值:FindBySubjectName,FindByThumbPrint,FindByIssuerName...... findValue - 对应查找方式的要查找证书的值 --> <clientCertificate storeName="存储区" storeLocation="存储位置" x509FindType="FindBySubjectName" findValue="Client1" /> <serviceCertificate> <authentication certificateValidationMode="None" /> </serviceCertificate> </clientCredentials> </behavior> </endpointBehaviors> </behaviors> <!-- 包含客户端跟服务端连接使用到的Endpoint的 配置 --> <client> <!-- 每个客户端Endpoint设置 属性说明: address - 对 应到服务端这个Endpoint的address binding - 指定这个Endpoint使用的binding,这个banding可以是系统预定义的9个binding之一, 比如是basicHttpBinding contract - 指 定这个Endpoint对应的Contract的 全限定名(名称空间.类型名) name - Endpoint的配置名,客户端代理类的构造方法中的endpointConfigurationName对 应到这个name bindingConfiguration - 指 定客户端binding的具体设置,指向元 素下同类型binding的name behaviorConfiguration - 指定这个endpoint的behavior,指向 下的同样配置名称的 --> <endpoint address="URI" binding="basicHttpBinding" bindingConfiguration="binding名" behaviorConfiguration="String" contract="Contract全限定名" name="endpoint配置名" > <!-- 用于客户端验证服务端身份,可选以下一种方式验证服务端--> <identity> <userPrincipalName></userPrincipalName> <servicePrincipalName></servicePrincipalName> <!--如果客户端验证是windows,这里指定DNS名;如果是Certificate, 这里指定证书subject name--> <dns></dns> <rsa></rsa> <!--指定服务端证书的公钥 属性说明: encodedValue - 服务端证书的公钥的base64编码,用于加密用户名和 密码--> <certificate encodedValue=""></certificate> <!-- 用户指定在客户端证书存储区内的服务端证书 属性说明: storeName - 证 书的存储区,可能值为:AddressBook,AuthRoot,CertificateAuthority Disallowed,My,Root,TrustedPeople,TrustedPublisher storeLocation - 证书存储位置,可能值为:CurrentUser,LocalMachine x509FindType - 查找证书的方式,可能的值:FindBySubjectName,FindByThumbPrint,FindByIssuerName...... findValue - 对应查找方式的要查找证书的值 --> <certificateReference storeName="存储区" storeLocation="存储位置" x509FindType="FindBySubjectName" findValue="Client1" /> </identity> </endpoint> </client> </system.ServiceModel> </configuration>
备份:
服务端
1 <?xml version="1.0" encoding="utf-8" ?> 2 <configuration> 3 <system.serviceModel> 4 <services> 5 <!--测试服务--> 6 <service name="CloudTraPlatSOAWcfService.Public.Services.ManagementService" behaviorConfiguration="SBeHavior"> 7 <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpNoneSecurityBind" 8 contract="CloudTraPlatSOAWcfService.Public.Contracts.IManagementContract" /> 9 <endpoint contract="IMetadataExchange" binding="mexTcpBinding" address="mex" /> 10 <host> 11 <baseAddresses> 12 <add baseAddress="net.tcp://192.168.0.77:9101/ManagementService"/> 13 </baseAddresses> 14 </host> 15 </service> 16 <!--公共库字典服务--> 17 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_Dictionary" behaviorConfiguration="SBeHavior"> 18 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 19 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_Dictionary"> 20 <identity> 21 <dns value="localhost" /> 22 </identity> 23 </endpoint> 24 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 25 <host> 26 <baseAddresses> 27 <add baseAddress="http://localhost:9001/InSideService_Dictionary" /> 28 </baseAddresses> 29 </host> 30 </service> 31 <!--企业库服务--> 32 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_EnterpriseLibrary" behaviorConfiguration="SBeHavior"> 33 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 34 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_EnterpriseLibrary"> 35 <identity> 36 <dns value="localhost" /> 37 </identity> 38 </endpoint> 39 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 40 <host> 41 <baseAddresses> 42 <add baseAddress="http://localhost:9001/InSideService_EnterpriseLibrary" /> 43 </baseAddresses> 44 </host> 45 </service> 46 <!--平台服务--> 47 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_PlatForm" behaviorConfiguration="SBeHavior"> 48 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 49 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_PlatForm"> 50 <identity> 51 <dns value="localhost" /> 52 </identity> 53 </endpoint> 54 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 55 <host> 56 <baseAddresses> 57 <add baseAddress="http://localhost:9001/InSideService_PlatForm" /> 58 </baseAddresses> 59 </host> 60 </service> 61 <!--上传工具服务--> 62 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_Upload" behaviorConfiguration="SBeHavior"> 63 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 64 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_Upload"> 65 <identity> 66 <dns value="localhost" /> 67 </identity> 68 </endpoint> 69 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 70 <host> 71 <baseAddresses> 72 <add baseAddress="http://localhost:9001/InSideService_Upload" /> 73 </baseAddresses> 74 </host> 75 </service> 76 <!--门户网站服务--> 77 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_WebSite" behaviorConfiguration="SBeHavior"> 78 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 79 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_WebSite"> 80 <identity> 81 <dns value="localhost" /> 82 </identity> 83 </endpoint> 84 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 85 <host> 86 <baseAddresses> 87 <add baseAddress="http://localhost:9001/InSideService_WebSite" /> 88 </baseAddresses> 89 </host> 90 </service> 91 <!--开标系统服务--> 92 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_OpenBid" behaviorConfiguration="SBeHavior"> 93 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 94 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_OpenBid"> 95 <identity> 96 <dns value="localhost" /> 97 </identity> 98 </endpoint> 99 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 100 <host> 101 <baseAddresses> 102 <add baseAddress="http://localhost:9001/InSideService_OpenBid" /> 103 </baseAddresses> 104 </host> 105 </service> 106 <!--保证金系统服务--> 107 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_Bail" behaviorConfiguration="SBeHavior"> 108 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 109 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_Bail"> 110 <identity> 111 <dns value="localhost" /> 112 </identity> 113 </endpoint> 114 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 115 <host> 116 <baseAddresses> 117 <add baseAddress="http://localhost:9001/InSideService_Bail" /> 118 </baseAddresses> 119 </host> 120 </service> 121 <!--金润内部其他系统接口--> 122 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.InSideService_JR" behaviorConfiguration="SBeHavior"> 123 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 124 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IInSideContract_JR"> 125 <identity> 126 <dns value="localhost" /> 127 </identity> 128 </endpoint> 129 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 130 <host> 131 <baseAddresses> 132 <add baseAddress="http://localhost:9001/InSideService_JR" /> 133 </baseAddresses> 134 </host> 135 </service> 136 <!--CA服务--> 137 <service name="CloudTraPlatSOAWcfService.Product.SXWT.Services.OutSideService_CA" behaviorConfiguration="SBeHavior"> 138 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MessageNoneSecurityPublic" 139 contract="CloudTraPlatSOAWcfService.Product.SXWT.Contracts.IOutSideContract_CA"> 140 <identity> 141 <dns value="localhost" /> 142 </identity> 143 </endpoint> 144 <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 145 <host> 146 <baseAddresses> 147 <add baseAddress="http://localhost:9001/OutSideService_CA" /> 148 </baseAddresses> 149 </host> 150 </service> 151 </services> 152 <bindings> 153 <wsHttpBinding> 154 <binding name="wsBinding" closeTimeout="00:10:00" openTimeout="00:10:00" 155 receiveTimeout="01:00:00" sendTimeout="01:00:00" allowCookies="false" 156 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 157 maxBufferPoolSize="999999999" maxReceivedMessageSize="999999999" 158 messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false"> 159 <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="999999999" 160 maxBytesPerRead="999999999" maxNameTableCharCount="999999999" /> 161 <reliableSession inactivityTimeout="01:00:00"/> 162 <security mode="Message"> 163 <!--定义消息级安全性要求的类型,为证书--> 164 <message clientCredentialType="Certificate" /> 165 </security> 166 </binding> 167 </wsHttpBinding> 168 <basicHttpBinding> 169 <binding name="MessageNoneSecurityPublic" closeTimeout="00:10:00" openTimeout="00:10:00" 170 receiveTimeout="01:00:00" sendTimeout="01:00:00" allowCookies="false" 171 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 172 maxBufferPoolSize="999999999" maxReceivedMessageSize="999999999" 173 messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false"> 174 <security mode="None" /> 175 <readerQuotas maxStringContentLength="9000000" maxArrayLength="9000000" /> 176 </binding> 177 </basicHttpBinding> 178 <netTcpBinding> 179 <binding name="tcpNoneSecurityBind" closeTimeout="00:10:00" openTimeout="00:10:00" 180 receiveTimeout="01:00:00" sendTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" 181 maxBufferPoolSize="999999999" maxReceivedMessageSize="999999999"> 182 <security mode="None" /> 183 <readerQuotas maxStringContentLength="9000000" maxArrayLength="9000000" /> 184 </binding> 185 <binding name="tcpSecurityBind" closeTimeout="00:10:00" openTimeout="00:10:00" 186 receiveTimeout="01:00:00" sendTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" 187 maxBufferPoolSize="999999999" maxReceivedMessageSize="999999999"> 188 <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="999999999" 189 maxBytesPerRead="999999999" maxNameTableCharCount="999999999" /> 190 <reliableSession inactivityTimeout="01:00:00"/> 191 <security mode="Message"> 192 <!--定义消息级安全性要求的类型,为证书--> 193 <message clientCredentialType="Certificate" /> 194 </security> 195 </binding> 196 </netTcpBinding> 197 </bindings> 198 <behaviors> 199 <serviceBehaviors> 200 <behavior name="SBeHavior"> 201 <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 --> 202 <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> 203 <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> 204 <serviceDebug includeExceptionDetailInFaults="false" /> 205 <serviceThrottling maxConcurrentSessions="200" maxConcurrentCalls="200" maxConcurrentInstances="200" /> 206 </behavior> 207 <behavior name="httpBehavior"> 208 <serviceMetadata httpGetEnabled="true"/> 209 <serviceThrottling maxConcurrentSessions="200" maxConcurrentCalls="200" maxConcurrentInstances="200" /> 210 <serviceCredentials> 211 <serviceCertificate findValue="JRNETSERVICE" x509FindType="FindBySubjectName" storeLocation="LocalMachine" 212 storeName="My" /> 213 <clientCertificate> 214 <!--自定义对客户端进行证书认证方式 这里为 None--> 215 <authentication certificateValidationMode="Custom" 216 customCertificateValidatorType="CloudTraPlatSOA.Tool.SafetyVerification.X509Validator,CloudTraPlatSOA"/> 217 </clientCertificate> 218 </serviceCredentials> 219 <serviceAuthorization serviceAuthorizationManagerType="CloudTraPlatSOA.Tool.SafetyVerification.CustomServiceAuthorizationManager,CloudTraPlatSOA"> 220 <authorizationPolicies> 221 <add policyType="CloudTraPlatSOA.Tool.SafetyVerification.CustomAuthorizationPolicy,CloudTraPlatSOA"/> 222 </authorizationPolicies> 223 </serviceAuthorization> 224 </behavior> 225 </serviceBehaviors> 226 </behaviors> 227 </system.serviceModel> 228 </configuration>
客户端tcp
1 <?xml version="1.0" encoding="utf-8" ?> 2 <configuration> 3 <system.serviceModel> 4 <bindings> 5 <netTcpBinding> 6 <binding name="NetTcpBinding_IManagementContract"> 7 <security mode="None" /> 8 </binding> 9 </netTcpBinding> 10 </bindings> 11 <client> 12 <endpoint address="net.tcp://192.168.0.77:9101/ManagementService" 13 binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IManagementContract" 14 contract="SR.IManagementContract" name="NetTcpBinding_IManagementContract" /> 15 </client> 16 </system.serviceModel> 17 </configuration>