- WCF Multi-layer Services Development with Entity Framework(Fourth Edition)
- Mike Liu
- 314字
- 2021-08-05 17:32:45
Implementing the HelloWorldService service contract
Now that we have defined a service contract interface, we need to implement it. For this purpose, we will re-use the empty class file that Visual Studio created for us earlier and modify it to make it the implementation class of our service.
Before we modify this file, we need to rename it. In the Solution Explorer window, right-click on the Class1.cs file, select Rename from the context menu, and rename it as HelloWorldService.cs
. Visual Studio is smart enough to change all the related files that are references to use this new name. You can also select the file and change its name from the Properties window.
Next, perform the following steps to customize the class file:
- Open the
HelloWorldService.cs
file. - Make it implement
IHelloWorldService
implicitly as follows:public class HelloWorldService: IHelloWorldService
- Add a
GetMessage
method to the class. This is an ordinary C# method that returns a string. You can also right-click on the interface link and select Implement Interface to add the skeleton of this method.public string GetMessage(string name) { return "Hello world from " + name + "!"; }
The final content of the HelloWorldService.cs
file should look like the following:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorldService { public class HelloWorldService: IHelloWorldService { public string GetMessage(string name) { return "Hello world from " + name + "!"; } } }
Now, build the project. If there is no build error, it means that you have successfully created your first WCF service. If you see a compilation error such as 'ServiceModel' does not exist in the namespace 'System', this is because you didn't add the System.ServiceModel
namespace reference correctly. Revisit the previous section to add this reference and you are all set.
Next, we will host this WCF service in an environment and create a client application to consume it.
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- Java 開發從入門到精通(第2版)
- PHP程序設計(慕課版)
- Machine Learning with R Cookbook(Second Edition)
- JavaScript+jQuery開發實戰
- 精通軟件性能測試與LoadRunner實戰(第2版)
- 利用Python進行數據分析(原書第3版)
- 大學計算機基礎實驗指導
- Visual Basic程序設計上機實驗教程
- Scratch·愛編程的藝術家
- Solutions Architect's Handbook
- 軟件工程與UML案例解析(第三版)
- 零基礎學編程系列(全5冊)
- Android初級應用開發
- Java Web應用開發