Windows Phone Workshop: WCF services

6
Workshop : consume WCF Services in Windows Phone application 2013 1 Objective Creating simple WCF Service Consuming WCF Service using Windows Phone application. WCF SERVICE STEP 1 First of all launch Visual Studio 2012. Click FILE->NEW->PROJECT. Create new "WCF Service Application". STEP 2 Once you create the project, you can see in solution that By Default WCF service and interface file are already created. You should create file as we will create our own interface and WCF service file. STEP 3 Now right click on solution and create one new WCF service file, and add two classes with your own name, in my case I will name the interface IWin7MobileService.cs and the class that will implement the interface Win7MobileService.svc.cs STEP 4 IWin7MobileService.cs defines the interface of the WCF Service. It has two methods which are essentially getter and setter methods.

Transcript of Windows Phone Workshop: WCF services

Page 1: Windows Phone Workshop: WCF services

Workshop : consume WCF Services in Windows Phone application 2013

1

Objective

Creating simple WCF Service

Consuming WCF Service using Windows Phone application.

WCF SERVICE

STEP 1

First of all launch Visual Studio 2012. Click FILE->NEW->PROJECT. Create new "WCF Service

Application".

STEP 2

Once you create the project, you can see in solution that By Default WCF service and interface file are

already created. You should create file as we will create our own interface and WCF service file.

STEP 3

Now right click on solution and create one new WCF service file, and add two classes with your own

name, in my case I will name the interface IWin7MobileService.cs and the class that will implement the

interface Win7MobileService.svc.cs

STEP 4

IWin7MobileService.cs defines the interface of the WCF Service. It has two methods which are essentially

getter and setter methods.

Page 2: Windows Phone Workshop: WCF services

Workshop : consume WCF Services in Windows Phone application 2013

2

STEP 5

Win7MobileService.svc.cs is an implementation of the interface. The class contains a static data member and

the implementation of the methods of the interface.

STEP 6

Web.config file defines essentially the <service> and <serviceBehaviors>. In your implementation, modify

the <baseAddresses> tag with the IP address of the machine

Page 3: Windows Phone Workshop: WCF services

Workshop : consume WCF Services in Windows Phone application 2013

3

Consume WCF using Windows Phone application

STEP 1

Create a new Windows Phone Application. Here, we will not modify manually any XAML code but will

make use of toolbox for controls. As shown below, I’ve made use

of TextBlock, TextBox and Button controls from toolbox.

Page 4: Windows Phone Workshop: WCF services

Workshop : consume WCF Services in Windows Phone application 2013

4

STEP 2

In order to consume deployed WCF Service, right click the project and select Add Service Reference. Enter

the address of the WCF Service (i.e. http://{IP

Address}/wcfserviceforwinmobile/win7mobileservice.svc?wsdl).

This will create ServiceReferences.ClientConfig file in the project. Now you can use WCF Service in your

Client application.

Page 5: Windows Phone Workshop: WCF services

Workshop : consume WCF Services in Windows Phone application 2013

5

STEP 3

The following is the MainPage.xaml.cs code:

Page 6: Windows Phone Workshop: WCF services

Workshop : consume WCF Services in Windows Phone application 2013

6