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

 

 

Soft Input Panel (SIP) Windows Phone 7

Dear Friends,

Input is must for any application and valid input provide best result which you want.

Windows phone 7 having SIP ( Soft Input Panel)  for input.

For example phone number should be numeric always personal name having alphabets only such kind of validation is required when we develop any application.

With windows phone 7 we have facility that keyboard automatically change according to input scope.

For example if we want numeric value in textbox than it shows numeric keys.

Below are the some patterns which windows phone support.   AddressCountryShortName

AddressStateOrProvince

AddressStreet

Chat

CurrencyAmount

Date

Digits

EmailNameOrAddress

Formula

Maps

Url

Time

You just need to add Input scope property to textbox and rest of the validation for input handle by Windows phone 7.

The SIP (Soft Input Panel) change according to Input scope.

For more detail see below screen.

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

Thanks & Best Regards,

Rajat Jaiswal

How take photo from Windows Phone 7 using code

Hello friends,

Today we will learn how to take photo from windows phone using code.

For this we will do following design we will have a button with name btnImage and text Take image.

We have an image control also on the page.

Now as we need to add same reference as we added in our previous 3 examples which is “Microsoft.Phone.Tasks”

Now on the  button click event we will write following code

CameraCaptureTask cameraTask = new CameraCaptureTask();
cameraTask.Show();

cameraTask.Completed += new EventHandler(cameraTask_Completed);

Now in the above code we have created a delegate in this delegate we will right following code

this.imgsrc.Source = PictureDecoder.DecodeJpeg(e.ChosenPhoto);

Here in the above line we are providing the capture image as a source code to our image control.

So when you click the take photo button you will get following screen.

And once you accept the photo you will get taken photo in image control of our windows phone app. So you are now aware how to capture image.

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

Enjoy doing taking Photos

Thanks & Best Regards,

Rajat Jaiswal

Send SMS from Windows Phone using code

Hello friends,

Earlier we have tried to call to a phone number using phone.

Now in this tutorial we will try to send SMS using windows phone app code.

So we just start with a new project.  We design phone screen with one textbox control which is use to enter phone number and one text box for SMS text. We place a button with name btnSMS and text SEND SMS. Please see below screen.

As similar to Phone call app we need to add Reference of  “Microsoft.Phone.Tasks”.

Now on the click on the button we need to write following code

SmsComposeTask smstask = new SmsComposeTask();

smstask.To = txtPhone.Text;

smstask.Body = txtbody.Text ;

smstask.Show();

Now when you run you will get following screen.

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

Enjoy doing SMS

Thanks & Best Regards,

Rajat Jaiswal

Simple code for calling from Windows Phone 7 using C# code

Hello friends,

Today I will explain how to make call using your C# code in Windows Phone.

It is very easy code you just need to write few lines and you are good to go. I will explain the concept of chooser and launchers later on please don’t worry about that right now.

So we start with a new project in which we add reference of Microsoft.Phone.Tasks.

On the screen we have added few names & there phone numbers textboxes.

We have added a call button for each name. Please see the below snap for design. Now in button click event you need to do following

  PhoneCallTask callTask = new PhoneCallTask();

callTask.DisplayName = this.txtName1.Text;

callTask.PhoneNumber = this.txtPhone1.Text;

callTask.Show();

Now when you click the call button you will find now you will get following screen which is a confirmation screen. In confirmation screen you will find the Display Name “Rajat Jaiswal” and phone number is there.

Now you can press call button and you will find you are calling Rajat Jaiswal at given number .

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

Enjoy calling

Rajat Jaiswal

How to set Windows Phone Page orientation in 5 minutes

Dear Friends,

Today we start with some basic but important feature for Windows Phone which is Orientation of screen.  As we know windows mobile phone is handy device a user can handle it any ways like portrait or landscape. Our main aim here is to change our screen orientation according to user action. Windows phone page has two properties for this activity.

When you open the XAML of the page in the phone application page you will find SupportedOrientations and Orientation by default these properties having value Portrait.

Support Orientations can have following property

a) Landscape  (It support Landscape view only)

b) Portrait     ( It support Portrait View only)

c) PortraitOrLandScape  (It support both View )

While Orientation can have following values

a) Landscape

b) Portrait

c) LandscapeLeft

d) LandscapeRight

e) PortraitUp

f) PortraitDown

g) None

To change the page layout we need to set  supportOrientation property to “portraitOrLandscape” And design the page in such a way that it automatically resize according to screen and take their position else you have to do programming for it to put control at proper place.

In current example I have use stack panel and in this stack panel I have used image control. To enable page orientation I have just change the support orientation property.  To know we are seeing which orientation I have added an event which is page orientation event.

You can say it will be simplest example for more information please download the project. (indiandotnet_Wp7_PageOrientation.zip)

https://skydrive.live.com/?cid=1eda2012469ff8ad&id=1EDA2012469FF8AD!243

 

Thanks & Best Regards,

Rajat Jaiswal