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

  • 相关阅读:
    socket编程中最常用的几个数据类型和转换函数
    windows下给QT可执行文件(exe)一个图标
    fseek函数与ftell函数使用例程
    LINUX C例程1:sscanf的用法
    Linux进程控制——exec函数族
    Linux查看文件编码格式及文件编码转换
    oracle易忘函数用法(1)
    Oracle VARRAY的实际应用简介
    oracle 存储过程的基本语法 及注意事项
    何将ext中的FormPanel中,所有组件都居中放置?
  • 原文地址:https://www.cnblogs.com/wuyansheng/p/WCF.html
Copyright © 2011-2022 走看看