Chapter 1 – Introducing Windows Communication Foundation

MS WCF 4 Step by Step

Introduction to WCF; how to create, deploy and access a simple WCF service.

Web Services: XML + XML Schema
Web Service ßà Web Service Client using SOAP. A web service can publish a Web Service Description language (WSDL) which is also XML, that describe the messages the web service can accept and the structure of the response. A client application can use this information to determine how to communicate with the web service.

JSON – Javascript Object Notation. Completely language-independent. It organizes data into name/value pairs, or collections of values.

SOA – service oriented architecture

WCF provides a model with which you can implment services that conforms to many commonly-accepted styles and standards, such as SOAP, XML, JSON. Additionally, WCF supports many MS-specific technologies for building components, such as Enterprises and MSMQ.

Building a WCF service (P. 9)

VS 2010 has several WCF project templates that you can use to build WCF service.
In this exercise, we’re building a WVF service that provides the following information:
(1) products sold by AdvWorks
(2) obtain details of a specific product
(3) Query the current stock level of a product
(4) Modify the stock level of a product

We will make use of .NET 4.0 Entity Framework. Purpose: provide an object mapping between tables in a database and a set of objects that you can use in your applications and services. Generate an object model that you can use to query tables, and inset/update/delete data. A major adv: you can build your applications that are independent of the underlying database management system.

Create a new C# project using the Class Library template, name “ProductEntityModel”, solution name: ProductService

Dele Class1.cs file. Add a new item – ADO.NET Entity Data Model template to the project, name: ProductModel.edmx. You see the wizard.

Select generate from Database:

Add a new connection to the AdvWorks database

In the next screen, select the tables; click Finish. VS 2010 generates the entity model.

On the next scrren, it dispay the tables and the table fields <-> Coding property relationship:

Build the project, next, add a new web site to the solution. Right click solution à Add à Add new web site.
Add a WCF service webs ite

Note: you can create WCF service as part of a web site; or library; or a standalone application, or WF.

The structure of WCF service enables you to adopt a “contract-first” approach to develop. First you define the “interface”, or contract (that the actual service will implement), and then build a service that conforms to these contracts. Adv: you can concentrate on designing your service. Separate definition from its implementation.

The Interface file includes: [ServiceContract] and [DataContract].

— ServiceContract
— OperationContract
— OperationContract
— OperationContract
— DataContract
— DataMember
— DataMember
— DataMember

Update with your own DataContract

Define ServiceContract (method interfaces)

Implementing the Service

You must implement every method defined b the service contract in the WCF service. If you define additional methods that are not in the service contract, those methods will not be visible to the client app.

In the WCF web site, add a reference to the ProductsEntityModel (Project) and System.Data.Entity (.NET) – required from fetching data from entity model.

Rename Service.cs to ProductsService.cs

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: