Consuming ASMX web services from Silverlight and WPF November 20, 2008
Posted by koolkatblog in ASP.NET.Tags: ASMX, Silverlight, WPF
trackback
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);
proxy.HelloWorldAsync();
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.
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!
Thanks for sharing this – it save me a lot of time.
This Really Helped to access some third party webservice