Friday, March 5, 2010

Delphi Prism ASP.NET web chat service

Using Delphi 2010, we can build ASP.NET web services and projects, as I often demonstrate in my ASP.NET workshops and training events (in The Netherlands, UK and Sweden for example). In this article, I'll demonstrate how we can use Delphi Prism and ASP.NET to write a web chat service, consuming it in an ASP.NET web form as well.
In order to participate with the demo of this month, you need a copy of Delphi Prism. After starting Delphi Prism, do File | New ?Project, and in the Web node of the Delphi Prism project types, select the ASP.NET Web Application. Specify WebChat as name of the application. This will create a new solution with one project called WebChat

Unfortunately, inside the generated source code in file chat.asmx.pas the [WebMethod] attribute still appears above the implementation of the example method chat.HelloWorld instead of the definition of this method in the chat class. We need to move that attribute from the implementation to the definition. In fact, we don't need the entire HelloWorld method at all, so feel free to remove both the definition and implementation.
For the chatroom example, I need two methods: one to send a chat message, and another to retrieve all chat messages.