Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

Silverlight and Web Services

Using a webservice in silverlight can be very problematic. It does not work out of the
box when you just add a web reference and try to use it. You will get a lot of
501 - Internal Server Errors, WebException - Error invoking service, etc.

Instead of repeating what so many people have already reported for Silverlight
and Web services I will just link to them and give you a small comment about
each link. My solution is below (it was something completely different than
the links I present here, but maybe I did not read all of them carefully).

  • Silverlight documentation about using remoting and webservices. Two solutions are presented, but the help is very short and if you have not done it before there can be many problems that are not discussed here. But this two ways are the standard solutions that almost everyone uses.

  • I used another solution to put all websites, web services and silverlight projects onto my IIS 7 server in Vista x64, but I had troubles debugging them. I moved also to IIS because it was annoying to test the website with the fun crashes VS Orcas gives you from time to time and it also has the advantage to show a working version on your colleagues computers by pointing to your computer's IIS.

        In short this is what I had to do to get debugging and executing working for web sites and web services in IIS7 with VS Orcas:
  • Install IIS (Internet Information Services) first, you can find it in the Control Panel -> Programs/Features -> Turn Windows features on or off.
  • Open the IIS tree and select the Web Management Tools (just install all of them). Also make sure you install ASP.NET in World Wide Web Services/  Application Development Features, it will also select all the other required components.
  • Last but not least select the Basic, IP, URL and Windows Authentications in the Security tree below World Wide Web Services.

  • After installing it you probably need to restart (it did not work without restarting at my colleagues computer). With the IIS Manager (in Computer Management) navigate to your Default Web Site and go into Authentication. Only Anonymous Authentication will be enabled, also enable Windows Authentication (and whatever else you need). You should also switch from the Default AppPool to the Classic .NET AppPool in the Default Web Site -> Right Click -> Advanced Settings -> Application Pool, else debugging will probably not work (Ctrl+F5 works fine even when you do not do this).
  • All websites you create from now will use the Classic .NET AppPool, if you already have websites in IIS, make sure to change them too if you want to debug them.
  • If you still cannot debug you probably do not have sufficiant rights for the user account that is used in IIS. I usually create a new account with Admin rights (plus password), set it to the IIS (Anonymous Authentication, click edit to select a new user) and then downgrade the Account until it does not work anymore, then you can set the appropriate rights (directory access, etc.) to the account. If you only use your IIS for yourself, you can also use your own user account for testing and debugging.

My problem however was the inability to access the web service via HTTP.
You can access it via SOAP and call the main page and execute the methods,
but directly calling Service.asmx/Method?Parameter=Value was not possible
and lead to the:
WebException - Error invoking service
and Internal Server Error
exceptions (depending on the mood and the way I used web services, I used
mainly the first method (Plain XML Requests over HTTP) as described here:

To test this I called the website directly the way described in the article
I used something like this:
This returned a 501 Internal Server Error (IIS7) or 404 The Page cannot be found
(IIS6), which means this kind of HTTP gets is not supported in this web service
right now. To fix this you have to activate HTTP get in the web.config file with the following code:
<add name="HttpGet"/>
<add name="HttpPost"/>

From the MSDN Help on activating HTTP Get and HTTP Post for web sites and web services.;en-us;819267

Hope this helps, make sure to read the articles mentioned above in detail if you still have issues.

Update 2007-07-14: BTW, if you are interested in webservices for ajax and silverlight,
check out this new project from microsoft live labs:
From the astoria website: "The new wave of web applications are built on technologies such as AJAX and Microsoft Silverlight that enable developers to build better, richer user experiences. These technologies bring a shift in how applications are organized, including a stronger separation of presentation from data.

The goal of Microsoft Codename Astoria is to enable applications to expose data as a data service that can be consumed by web clients within a corporate network and across the internet. The data service is reachable over HTTP, and URIs are used to identify the various pieces of information available through the service. Interactions with the data service happens in terms of HTTP verbs such as GET, POST, PUT and DELETE, and the data exchanged in those interactions is represented in simple formats such as XML and JSON.

We are delivering this first early release of Astoria as a Community Tech Preview you can download and also as an experimental online service you can access over the internet."

Comments (1) -

  • Naples Real Estate

    4/13/2010 7:42:09 PM |

    That’s quite a blog.  Hah, well I will check back later.  So you got my bookmark…

Comments are closed