Tuesday, December 18, 2012

The use of SOAP web services in windows phone applications


we can use the soap web services in our windows phone application as a client for this purpose we just need to follow few steps for the understanding purpose i wants to use a web link

http://www.wsdl2code.com/SampleService.asmx

and wsdl services of this link

http://www.wsdl2code.com/SampleService.asmx?wsdl

now we have to follow few steps as follows

1) just make an Application on yours silverlight WSDLservices
2) In the solution explorer right click on the "Service Reference" , click on "ADD service reference" fill the field with the link
http://www.wsdl2code.com/SampleService.asmx?wsdl

 and fill the Namespace as  ".SampleService. click ok"




now you have a view as above  given image

3) now run the progran you can see it as follows




4) just write the code on yours MainPage.xaml.cs as folllows


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WSDLservices.SampleService;
namespace WSDLservices
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            SampleService.SampleServiceSoapClient client = new SampleServiceSoapClient();
            client.HelloWorldCompleted += new EventHandler<HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
            client.HelloWorldAsync();
        }
        void client_HelloWorldCompleted(object sender, HelloWorldCompletedEventArgs e)
        {
            PageTitle.Text = e.Result.ToString();
        }
    }
}

 now run the program and get the response over yours emulator as follows


Now you can use the other methods of the web service in same manner. have a great day ahead :)

2 comments:

  1. Thanks,

    But i am getting some times time out error. How can we increase time out or define time out while calling web service method?

    ReplyDelete
    Replies
    1. Hi Please check the api, you will get some method or constants i think

      Delete