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

  • 相关阅读:
    SpringBoot 部署【war】到服务器的tomcat
    SpringBoot 部署【jar】前后端分离(nginx)
    VM安装centos7
    nginx 入门
    《从零开始学习Mysql5.7》笔记
    架构师技术栈
    【读书笔记】小强升职记
    lambda 表达式
    【软考】信息资料
    flutter 获取状态栏高度
  • 原文地址:https://www.cnblogs.com/wuyansheng/p/WCF.html
Copyright © 2011-2022 走看看