WCF服务的承载方式和选择参考

上篇文章:WCF经典使用场景(互联网、局域网、匿名等)总结和例子 http://www.cnblogs.com/2018/archive/2011/02/26/1965569.html

对WCF的使用进行分类的介绍,实际开发完成涉及到部署的问题,根据如下的资料参考实际情况选择部署方式

部署方式:自承载、IIS承载和Appfabric承载

IIS服务承载

使用svc扩展实现,如下配置

<add path="*.svc"

verb="*"

type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

validate="false" />

</httpHandlers>

如何使IIS能够承载net.tcp等其他协议

两步配置:

网站绑定加上net.tcp

clip_image002

支持的协议增加net.tcp

clip_image004

然后添加的svc服务自动就支持了http和net.tcp绑定

手动设置无svc文件的服务

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<!--无svc的服务,须在IIS中net.tcp协议才能启用-->
<add relativeAddress="demo.svc" service="WCfSvc.DemoWcf" />
</serviceActivations >
</serviceHostingEnvironment>
  <services>
<service name="WCfSvc.DemoWcf">
<!--多个终结点的不同协议支持-->
<endpoint address="ws" binding="wsHttpBinding" name="http" contract="Contracts.ICarRentalService"/>
<endpoint binding="basicHttpBinding" name="http" contract="Contracts.ICarRentalService"/>
<endpoint binding="netTcpBinding" name="tcp" contract="Contracts.ICarRentalService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors

Hosting的选择

clip_image006

根据以上的表选择适合的部署方式即可

原文地址:https://www.cnblogs.com/2018/p/1957372.html