WCF服务配置(1)

https://www.cnblogs.com/ingstyle/p/5711249.html

1 service.name必须对应服务的实现类限定名
2 baseAddresses定义服务基地址,可以为不同的传协议提供不同的基地址,
一个服务一种传输协议最多一个基地址。
WCF中支持的传输协议如下:
a Http地址:http://ip:port/
b Tcp地址:net.tcp://ip:prot/
c IPC地址:net.pipe://ip/(适用于跨进程,不是使用于不同机器间)
d MSMQ地址:net.msmq://ip/
e 对等网地址:net.p2p://ip/
3 endpoint.address 可以使用相对路径(基地址+address),也可使用绝对路径。并根据绑定的类型自动匹配基地址。
4 endpoint.binding 定义绑定的类型。
5 endpoint.contract 配置服务契约(接口)的限定名。
6 endpoint[address="mex"] 原数据端点,有了它就能在客户端通过添加服务引用来生成客户端代理类,一个服务配置一个数据交换端点就够了。(?wsdl访问)
7 配合"原数据端点"。在behaviors.serviceBehaviors.behavior 中配置是否原型Get检索。
8 behaviors.serviceBehaviors.behavior.serviceDebug,为True那么,WCF将服务端的错误内容传递给客户端,在客户端可以获得更加具体的错误信息。

<!--WCF中提供的绑定有:-->
<!--1 最简单的绑定类型,通常用于WebServices。使用Http协议,Text/xml编码方式。-->
<basicHttpBinding ></basicHttpBinding>
<!--2 比basicHttpBinding更加安全,通常用于non-duplex(非双工)服务通讯。-->
<wsHttpBinding></wsHttpBinding>
<!--3 和wsHttpBinding相比,它支持duplex类型的服务。-->
<wsDualHttpBinding></wsDualHttpBinding>
<!--4 支持WS-Federation安全通讯协议。-->
<wsFederationHttpBinding></wsFederationHttpBinding>
<!--5 效率最高,安全的跨机器通讯方式。-->
<netTcpBinding></netTcpBinding>
<!--6 安全、可靠、高效的单机服务通讯方式。-->
<netNamedPipeBinding></netNamedPipeBinding>
<!--7 使用消息队列在不同机器间进行通讯。-->
<netMsmqBinding></netMsmqBinding>
<!--8 使用P2P协议在多机器间通讯。-->
<netPeerTcpBinding></netPeerTcpBinding>
<!--9 使用现有的消息队列系统进行跨机器通讯。-->
<msmqIntegrationBinding></msmqIntegrationBinding>
<!--....-->

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3 
 4   <appSettings>
 5     <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
 6   </appSettings>
 7   <system.web>
 8     <compilation debug="true" />
 9   </system.web>
10   <!-- 部署服务库项目时,必须将配置文件的内容添加到
11  主机的 app.config 文件中。System.Configuration 不支持库的配置文件。 -->
12   <system.serviceModel>
13     <!-- 1 service.name必须对应服务的实现类限定名 
14            2 baseAddresses定义服务基地址,可以为不同的传协议提供不同的基地址,
15               一个服务一种传输协议最多一个基地址。
16               WCF中支持的传输协议如下:
17               a Http地址:http://ip:port/
18               b Tcp地址:net.tcp://ip:prot/
19               c IPC地址:net.pipe://ip/(适用于跨进程,不是使用于不同机器间)
20               d MSMQ地址:net.msmq://ip/
21               e 对等网地址:net.p2p://ip/
22            3 endpoint.address 可以使用相对路径(基地址+address),也可使用绝对路径。并根据绑定的类型自动匹配基地址。
23            4 endpoint.binding 定义绑定的类型。
24            5 endpoint.contract 配置服务契约(接口)的限定名。
25            6 endpoint[address="mex"] 原数据端点,有了它就能在客户端通过添加服务引用来生成客户端代理类,一个服务配置一个数据交换端点就够了。(?wsdl访问)
26            7 配合"原数据端点"。在behaviors.serviceBehaviors.behavior 中配置是否原型Get检索。
27            8 behaviors.serviceBehaviors.behavior.serviceDebug,为True那么,WCF将服务端的错误内容传递给客户端,在客户端可以获得更加具体的错误信息。
28       -->
29     <services>
30       <service name="WcfServiceLibrary1.Service1">
31         <host>
32           <baseAddresses>
33             <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
34           </baseAddresses>
35         </host>
36         <!-- Service Endpoints -->
37         <!-- 除非完全限定,否则地址相对于上面提供的基址-->
38         <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
39           <!-- 
40               部署时,应删除或替换下列标识元素,以反映
41              用来运行所部署服务的标识。删除之后,WCF 将
42               自动推断相应标识。
43           -->
44           <identity>
45             <dns value="localhost"/>
46           </identity>
47         </endpoint>
48         <!-- Metadata Endpoints -->
49         <!-- 元数据交换终结点供相应的服务用于向客户端做自我介绍。 --> 
50         <!-- 此终结点不使用安全绑定,应在部署前确保其安全或将其删除-->
51         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
52       </service>
53     </services>
54     <behaviors>
55       <serviceBehaviors>
56         <behavior>
57           <!-- 为避免泄漏元数据信息,
58           请在部署前将以下值设置为 false -->
59           <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
60           <!-- 要接收故障异常详细信息以进行调试,
61           请将以下值设置为 true。在部署前设置为 false 
62           以避免泄漏异常信息 -->
63           <serviceDebug includeExceptionDetailInFaults="False" />
64         </behavior>
65       </serviceBehaviors>
66     </behaviors>
67     <bindings>
68       <!--WCF中提供的绑定有:-->
69       <!--1 最简单的绑定类型,通常用于WebServices。使用Http协议,Text/xml编码方式。-->
70       <basicHttpBinding ></basicHttpBinding>
71       <!--2 比basicHttpBinding更加安全,通常用于non-duplex(非双工)服务通讯。-->
72       <wsHttpBinding></wsHttpBinding>
73       <!--3 和wsHttpBinding相比,它支持duplex类型的服务。-->
74       <wsDualHttpBinding></wsDualHttpBinding>
75       <!--4 支持WS-Federation安全通讯协议。-->
76       <wsFederationHttpBinding></wsFederationHttpBinding>
77       <!--5 效率最高,安全的跨机器通讯方式。-->
78       <netTcpBinding></netTcpBinding>
79       <!--6 安全、可靠、高效的单机服务通讯方式。-->
80       <netNamedPipeBinding></netNamedPipeBinding>
81       <!--7 使用消息队列在不同机器间进行通讯。-->
82       <netMsmqBinding></netMsmqBinding>
83       <!--8 使用P2P协议在多机器间通讯。-->
84       <netPeerTcpBinding></netPeerTcpBinding>
85       <!--9 使用现有的消息队列系统进行跨机器通讯。-->
86       <msmqIntegrationBinding></msmqIntegrationBinding>
87       <!--....-->
88     </bindings>
89   </system.serviceModel>
90 
91 </configuration>
View Code