- WCF Multi-layer Services Development with Entity Framework(Fourth Edition)
- Mike Liu
- 257字
- 2021-08-05 17:32:44
Defining the HelloWorldService service contract interface
In the previous section, we created the solution and the project for the HelloWorld
WCF service. From this section onwards, we will start building the HelloWorld
WCF service. First, we need to define the service contract interface. For this, perform the following steps:
- In the Solution Explorer, right-click on the HelloWorldService project and select Add | New Item… from the context menu. The Add New Item dialog window shown in the following screenshot will appear on your screen:
- On the left-hand side of the window, select Installed | Visual C# Items as the template, and from the middle section of the window, select Interface.
- At the bottom of the window, change Name from
Interface1.cs
toIHelloWorldService.cs
. - Click on the Add button.
Now an empty service interface file has been added to the project, which we are going to use as the service interface. Follow these steps to customize it:
- Add a
using
statement:using System.ServiceModel;
- Add a
ServiceContract
attribute to the interface. This will designate the interface as a WCF service contract interface:[ServiceContract]
- Add a
GetMessage
method to the interface. This method will take a string as the input and return another string as the result. It also has an attribute calledOperationContract
:[OperationContract] string GetMessage(string name);
- Change the interface to public.
The final content of the file, IHelloWorldService.cs
, should look as follows:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceModel; namespace HelloWorldService { [ServiceContract] public interface IHelloWorldService { [OperationContract] string GetMessage(string name); } }
推薦閱讀
- 精通JavaScript+jQuery:100%動態網頁設計密碼
- 深入理解Java7:核心技術與最佳實踐
- Internet of Things with Intel Galileo
- Visual C++數字圖像處理技術詳解
- 軟件工程
- Python機器學習基礎教程
- Julia高性能科學計算(第2版)
- Babylon.js Essentials
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- HTML+CSS+JavaScript編程入門指南(全2冊)
- Principles of Strategic Data Science
- Web前端開發最佳實踐
- Flink核心技術:源碼剖析與特性開發
- Getting Started with JUCE
- C# 10核心技術指南