jump to navigation

Consuming ASMX web services from Silverlight and WPF November 20, 2008

Posted by koolkatblog in ASP.NET.
Tags: , ,

I have just started writing some applications in Silverlight and WFP. I have many existing ASMX web services that I still need to use. Here is how you go about it.

For Silverlight:

1. Add a Service Reference to your Silverlight project . For my example, I called it ServiceReferenceTest1

2. In your code where you want to make the call, add the following code.
    (Intellisense will help).
    One note: The call must be asynchronous

   ServiceReferenceTest1.Service1SoapClient proxy = new ServiceReferenceTest1.Service1SoapClient();         

   proxy.HelloWorldCompleted +=
           new EventHandler(proxy_HelloWorldCompleted);


3. Provide the event for the completion of the asynchronous call.
    This example just returns the string “Hello World”.

    void proxy_HelloWorldCompleted(object sender,
          StationCasinosPostCards.ServiceReferenceTest1.HelloWorldCompletedEventArgs e)
       String result = e.Result.ToString();

For WPF:

1. Add a Service Reference but make sure you add it as a web reference.

Add Service Reference

Add as a Web Reference

Browse for Web Service

2. Add the call ( again, Intellisense helps).   My example returns a dataset.

    DataSet ds = new DataSet();
    ScratchCardServices.Service1 sr1 = new ScratchCardServices.Service1();
    ds = sr1.GetPrizeData(4408603);

Hope this helps!


1. David Roh - November 21, 2008

Thanks for sharing this – it save me a lot of time.

2. Kavita - July 11, 2011

This Really Helped to access some third party webservice

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: