首页 > Web开发 > 详细

dotNet Linux 学习记录 - Jexus寄宿 简单WCF服务

时间:2017-04-06 21:09:56      阅读:291      评论:0      收藏:0      [点我收藏+]

{0}

 

{0}

 

using System.ServiceModel;

namespace IBLL
{
    /// <summary>
    /// 服务契约接口
    /// </summary>
    [ServiceContract]
    public interface IWcfDemoService
    {
        /// <summary>
        /// 一个操作契约 (等同于WebService中的WebMethod)
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        [OperationContract]
        int Add(int a, int b);
    }
}

 

 

 

{1}

 

 

using IBLL;

namespace BLL
{
    /// <summary>
    /// 实现服务契约业务类
    /// </summary>
    public class WcfDemoService: IWcfDemoService
    {
        public int Add(int a, int b)
        {
            return a + b;
        }
    }
}

 

 

 {2}

1、新建一个空的WebApplication项目 WcfApp

2、新建一个 类文件 名为WcfTestService.cs

3、将 WcfTestService.cs 重命名为 WcfTestService.svc

4、将 WcfTestService.svc 中的内容清空,写入内容(Service 的值 为 Web.config 中 service 节点的 name 属性值相同)

<%@ ServiceHost Service="BLL.WcfDemoService" %>

 

5、修改 WcfApp 的 Web.config 文件内容

    注:  serivce节点中 name属性的值必须为服务契约实现业务类的类名

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <customErrors mode="Off"/>
  </system.web>

  
  <!-- WCF 配置开始 -->
  <system.serviceModel>

    <services>
      <!-- 注意: 服务名称必须与服务实现的配置名称相匹配。 -->
      <service name="BLL.WcfDemoService" behaviorConfiguration="BLL.WcfDemoService" >
        <!-- 添加下列终结点。 -->
        <!-- 注意: 服务必须有一个 http 基址以便添加此终结点。 -->
        <endpoint contract="IBLL.IWcfDemoService" binding="mexHttpBinding" address="mex" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="BLL.WcfDemoService" >
          <!-- 将下列元素添加到服务行为配置中。 -->
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>
  <!-- WCF 配置结束 -->
  

</configuration>

 

dotNet Linux 学习记录 - Jexus寄宿 简单WCF服务

原文:http://www.cnblogs.com/staneee/p/6675198.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!