WCF全面解析之三 使用配置文件启动WCF服务

知识:WCF地址、WCF绑定 Endpoint的配置

服务的三要素(ABC)

A:Address 地址 有传输方式信息

B:Binding 怎么做(与地址的传输方式要匹配)

C:Contract 做什么 (服务契约)

<Services>

  <endpoint/> /*服务和终结点*/

</Services>

<bindings>

  <binding></binding> /*端点地址定义*/ 终结点地址由EndpointAddress 类表示

</bindings>

<behaviors>

  <behavior></behavior>/*行为*/

</behaviors>

配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WindowsFormsA1.MyClass" behaviorConfiguration="testBehavior"> name为实现接口类
<host>
<baseAddresses>
<add baseAddress="http://localhost:8002/test"/> /*基地址*/
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="ClassLibrary1.myInterface"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="testBehavior">
<serviceMetadata httpGetEnabled="true"/> <!--允许获得原数据-->
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

猜你喜欢

转载自www.cnblogs.com/ltbhltbh/p/12327237.html
WCF
今日推荐