Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WCF Multi-layer Services Development with Entity Framework - Fourth Edition

You're reading from   WCF Multi-layer Services Development with Entity Framework - Fourth Edition Create and deploy complete solutions with WCF and Entity Framework

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher
ISBN-13 9781784391041
Length 378 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Mike Liu Mike Liu
Author Profile Icon Mike Liu
Mike Liu
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Implementing a Basic HelloWorld WCF Service FREE CHAPTER 2. Hosting the HelloWorld WCF Service 3. Deploying the HelloWorld WCF Service 4. Debugging the HelloWorld WCF Service 5. Implementing a Three-layer WCF Service 6. Adding Database Support and Exception Handling 7. LINQ to Entities – Basic Concepts and Features 8. LINQ to Entities – Advanced Concepts and Features 9. Applying LINQ to Entities to a WCF Service 10. Distributed Transaction Support of WCF 11. Building a RESTful WCF Service 12. WCF Security 13. Extending WCF Services Index

Creating the HelloWorld solution and project

Now that we have a basic understanding of WCF concepts and terminologies, let's start building a simple HelloWorld WCF service. Before we can build the WCF service, we need to create a solution for our service project. We also need a directory in which we will save all the files. Throughout this book, we will save our project source codes in the C:\SOAwithWCFandEF\Projects directory. We will have a subfolder for each solution we create, and under this solution folder we will have one subfolder for each project.

Note

You don't need to manually create these directories with Windows Explorer; Visual Studio will create them automatically when you create the solutions and projects.

Now, follow these steps to create our first solution and the HelloWorld project:

  1. Start Visual Studio 2013 (you can use Visual Studio Ultimate, Premium, or Professional throughout this book). If the Open Project dialog box pops up, click on Cancel to close it.
  2. Go to menu FILE | New | Project.... The New Project dialog window will appear, as follows:
    Creating the HelloWorld solution and project
  3. From the left-hand side of the window, expand Installed | Templates | Other Project Types and then select Visual Studio Solutions as the template. From the middle section of the window, select Blank Solution.
  4. At the bottom of the window, type in HelloWorld in the Name field and enter C:\SOAwithWCFandEF\Projects\ in the Location field. Note that you should not enter HelloWorld within the location, because Visual Studio will automatically create a new folder for us inside the Projects folder.
  5. Click on the OK button to close this window, and your screen should look like the following screenshot with an empty solution:
    Creating the HelloWorld solution and project
  6. Depending on your settings, the layout might be different. However, you should still have an empty solution in your Solution Explorer. If you don't see the Solution Explorer, navigate to VIEW | Solution Explorer or press Ctrl + Alt + L to bring it up.
  7. In the Solution Explorer, right-click on the solution and select Add | New Project… from the context menu. You can also go to FILE | Add | New Project… to get the same result. The following screenshot shows the context menu to add a new project:
    Creating the HelloWorld solution and project
  8. The New Project window should now appear on your screen. On the left-hand side of this window, select Installed | Visual C# as the template, and in the middle section of the window, select Class Library.
  9. At the bottom of the window, type in HelloWorldService in the Name field. Leave C:\SOAwithWCFandEF\Projects\HelloWorld in the Location field. Again, don't add HelloWorldService to the location, as Visual Studio will create a subfolder for this new project (Visual Studio will use the HelloWorld folder as the default base folder for all the new projects added to the solution). Refer to the following screenshot:
    Creating the HelloWorld solution and project

    You might have noticed that there is already a template for a WCF Service Application in Visual Studio 2013. For this very first example, we will not use this template. Instead, we will create everything by ourselves to understand the purpose of each template. This is an excellent way for you to understand and master this new technology. In the next chapter, we will use this template to create the project, so we don't need to manually type a lot of code.

  10. Now you can click on the OK button to close this window.

    Once you click on the OK button, Visual Studio will create several files for you. The first file is the project file. This is an XML file under our project's directory and it is called HelloWorldService.csproj.

    Visual Studio also creates an empty class file called Class1.cs. Later, we will change this default name to a more meaningful one.

    The window on your screen should now look like the one shown in the following screenshot:

    Creating the HelloWorld solution and project

We have now created a new solution and a new project. Next, we will develop and build this project as a new service. However, before we go any further, we need to do one more thing to this project. Click on the Show All Files button on the Solution Explorer toolbar as shown in the preceding screenshot. Clicking on this button will show all files and directories in your hard disk under your project's folder—even those items that are not included in the project. Make sure that you don't have the solution item selected, otherwise you cannot see the Show All Files button.

Lastly, in order to develop a WCF service, we need to add a reference to the System.ServiceModel assembly. Perform the following steps:

  1. In the Solution Explorer window, right-click on the HelloWorldService project and select Add | Reference… from the context menu. You can also right-click on References and select Add Reference… or go to PROJECT | Add Reference… to do this. The Reference Manager dialog window will appear on your screen as follows:
    Creating the HelloWorld solution and project
  2. Check the checkbox in front of System.ServiceModel from the Framework tab under Assemblies and click on OK.

Now in Solution Explorer, if you expand the references of the HelloWorldService project, you will see that System.ServiceModel has been added under References. Also, note that System.Xml.Linq is added by default. We will use this later when we query a database.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You have been reading a chapter from
WCF Multi-layer Services Development with Entity Framework - Fourth Edition
Published in: Oct 2014
Publisher:
ISBN-13: 9781784391041
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime