WCF服务器搭建-服务Host篇(Spring.net实现host)
因为一直以来对开源的框架也有一定的涉足,所以我自然而然就在想spring.net有没有对WCF服务进行方便管理的支持。答案是肯定的,所以spring.net也发挥了其IOC的优势,看我们如何来实现通过Spring.net Host WCF Service吧。
1、首先添加Spring.Core的引用,配置文件添加
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
<resource uri="assembly://MeiyaWCFHost/MeiyaWCFHost.Config/Services.xml"/>
</context>
<objects xmlns="http://www.springframework.net"/>
<!--必要-->
</spring>
2、Services.xml文件,即WCF服务类的文件,其中包括具体服务的类的注入,具体如下:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net
http://www.springframework.net/xsd/spring-objects.xsd">
<object id="BuyFruit" type="WCFServiceDemo.BuyFruit,WCFServiceDemo">
</object>
<object id="BuyFruitHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
<property name="TargetName" value="BuyFruit" /><!--BuyFruit名称需和spring.netObject名称一直,需和WCF 服务名称一致-->
</object>
</objects>
3、WCF服务配置如下:
<service name="BuyFruit" behaviorConfiguration="WcfServerBehavior">
<endpoint binding="netTcpBinding" contract="WCFContractDemo.IBuyFruit" bindingConfiguration="ServerBinding" address=""/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:3287/MeiyaWcf/IBuyFruit"/>
</baseAddresses>
</host>
</service>
4、最后,在host的应用程序上加上代码段: ContextRegistry.GetContext();
posted on 2012-03-08 15:51 wu-yansheng 阅读(470) 评论(4) 编辑 收藏 举报