標籤: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服務