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();