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();

  • 相关阅读:
    Android 8.0编译过程
    Ubuntu下映射网络驱动器
    Android 指定调用已安装的某个“相机”App
    sendMessage 与 obtainMessage (sendToTarget)比较
    Linux tee命令
    Android P(9.0) userdebug版本执行adb remount失败
    adb shell get/setprop, setenforce...
    Bluedroid: 蓝牙协议栈源码剖析
    android o logcat read: unexpected EOF!
    Winform 打包 混淆 自动更新
  • 原文地址:https://www.cnblogs.com/wuyansheng/p/WCF.html
Copyright © 2011-2022 走看看