zoukankan      html  css  js  c++  java
  • WCF服务器搭建服务Host篇(Spring.net实现host) wu

    因为一直以来对开源的框架也有一定的涉足,所以我自然而然就在想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();

  • 相关阅读:
    [Python Study Notes]with的使用
    [Python Study Notes]pynput实现对键盘控制与监控
    [Python Study Notes]pynput实现对鼠标控制
    [Python Study Notes]WdSaveFormat 枚举
    voip通话分析(含语音质量)
    纯Python给ulaw wav文件加头
    BAE+Python+Django+Wechatpy+Baidu weather api +微信订阅号 = 实现微信查询天气
    Python爬虫抓取某音乐网站MP3(下载歌曲、存入Sqlite)
    Python调用C++DLL函数出错String类型问题
    聊聊Python ctypes 模块(转载)
  • 原文地址:https://www.cnblogs.com/wuyansheng/p/WCF.html
Copyright © 2011-2022 走看看