Currently, you”ll only get tool support for ASMX web services that render JSON. This doesn”t mean that you can”t call a traditional ASMX web service (or even a WCF service). It only means that you”ll need to handle the XML yourself. Today, I”m only going to talk about my ASMX web service calls tests. So, if you have a ASMX web service, you need to:
1. remove the traditional asmx handle and add the new ScriptHandlerfactory that was introduced by the ASP.NET AJAX extensions. If you”re using IIS 6, this means that you have to add something like this to the handlers section of your web.config file:
<remove verb=”*” path=”*.asmx”/>
<add verb=”*” path=”*.asmx” validate=”false”
type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>
2. You need to decorate your web service class with the ScriptServiceAttribute and your public callable methods with the ScriptMethodAttribute attribute.
3. You should create a proxy to call the web service by using the slwsdl.exe tool. If you have VS orcas, then just add a reference to your web service (it”ll do the right thing)
4. Don”t forget to update the Url property of the proxy so that you don”t get a cross-domain exception. Don”t forget that in the current release you can only call “local” web services (and yes, different ports means a cross-domain call). Getting a cross-domain exception might happen more easily than you expect. For instance,this might happen if you”re using the internal server to build the site that hosts the silverlight control and you”ve added a reference to the web service through VS orcas (in my test,it just hard-coded the port that was being used by the internal server and then i got into trouble when i accessed it through a localhost call – which went through the IIS server). Since you must put everything on the same web site, why not play safe and just add something like this in your C# code before calling the method:
webServiceReference.Url = “relative_path_to_your_web_service.asmx”;
4. If you can, use async services. Even though the current release”s support for multithreading sucks, we can call a web service asynchronously and then update the user interface without getting an exception (which means that the callback is being called on the correct thread).
And you should be ready to go.