官术网_书友最值得收藏!

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:

  1. 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:
  2. 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.
  3. At the bottom of the window, change Name from Interface1.cs to IHelloWorldService.cs.
  4. 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:

  1. Add a using statement:
    using System.ServiceModel;
  2. Add a ServiceContract attribute to the interface. This will designate the interface as a WCF service contract interface:
    [ServiceContract]
  3. 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 called OperationContract:
    [OperationContract]
    string GetMessage(string name);
  4. 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);
    }
}
主站蜘蛛池模板: 阿拉善左旗| 麻阳| 社旗县| 舒兰市| 平顶山市| 师宗县| 施甸县| 清水县| 赤城县| 襄垣县| 襄垣县| 襄垣县| 和田县| 论坛| 北川| 盐津县| 旺苍县| 中江县| 梅州市| 东平县| 南木林县| 贵南县| 沽源县| 泸西县| 朝阳市| 叙永县| 通河县| 玉树县| 顺昌县| 宝鸡市| 诸城市| 渭源县| 赤城县| 繁昌县| 当雄县| 温宿县| 绥芬河市| 三门峡市| 秦安县| 陇南市| 湟中县|