Jun 11

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=, 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.

5 comments so far

  1. Reece Sim
    7:06 am - 11-1-2007


    I don”t quite get everything that you say. Can I get a full sample?

    My email address is

  2. Samuel
    10:28 pm - 1-2-2008

    Hello there, I am currently writing my thesis on rich web apps with silverlight… the 4th point( calling cross domain..) is actually burning me up… i tried to test to download an image from another server, not hosted on my machine and silverlight complained about runtime error…How can i pass through this..?

  3. karthik
    12:22 pm - 3-4-2008

    im getting cross domain calls are not supported byHttpWebrequest to resolve this error

  4. sss
    9:58 pm - 12-21-2008

    add a crossdomain.xml file to the target server

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>