Easy steps to call WCF service in Windows Phone 7

Dear All,

Today we will learn how to connect WCF service with Windows phone.

So let’s start with step by step I am using one of the best templates which Windows Phone 7 support it is data bound template.

We add WCF service project to same solution.

Image

We have created a WCF service which returns Category Id, Category name, Category description from Games database. For this we have created a custom data contract as shown in below fig

Image

Now we added the reference of this service to our windows phone project using add service reference menu which comes when we right click on windows phone project.

Once the service reference is added we won half battle now the next challenge is call the method of this service in our windows phone 7 projects. As you know the first step is to create an object of this service which we can do with following code.

 DataServiceFreeTips.CategoryInterfaceClient proxy = new DataServiceFreeTips.CategoryInterfaceClient();

Now all the services which we call using service reference always support asynchronous calling so.

We first create a handler which give us hint when the service get all the data to do this we write following code. And after this service call we call the actual service asynchronous method.

   proxy.GetCategoryCompleted += new EventHandler<DataServiceFreeTips.GetCategoryCompletedEventArgs>(proxy_GetCategoryCompleted);
            proxy.GetCategoryAsync();

Now we are good to go and now we will run it and see. We will get the entire category game list as shown in below fig.

Image

In this way we can call a WCF service.

For detail you can download the code from

You can download the code at https://skydrive.live.com/?cid=1eda2012469ff8ad&id=1EDA2012469FF8AD!243

Thanks & Best Regards,

Rajat Jaiswal

 

 

Advertisements

One thought on “Easy steps to call WCF service in Windows Phone 7

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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