dotNet Linux 學習記錄 - Jexus寄宿 簡單WCF服務

來源:互聯網
上載者:User

標籤:system   ice   bin   ada   off   匹配   簡單   業務   nbsp   

{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服務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.