- More Silverlight, Less Steve
-
I am leaving Microsoft France to start a new adventure. You may contact my architect collegues to discuss interoperability : Thomas Conté and Xavier Warzee.
- Eclipse4SL : M2 released + REST and SOAP Guidance
-
The Eclipse Tools for Silverlight enter year 2009 after achieving its 2008 commitments !
First of all, SOYATEC did a great job at correcting more than 30 bugs (and 200 unit tests to ensure first quality) but also at enhancing the plug-in to provide a better support for Silverlight (improvement of the XAML editor, support for Styles and Embedded Custom Components in XAML preview…).
To get the full list of features, see this detailed blog entry: Release 1.0.0 M2 is ready. Moreover, when you install the plug-in, you are now given the options to also install the source code and/or documentation.
Second, guidance is now provided to connect Silverlight applications to Java business logic. Because REST and SOAP make sense, we chose to provide guidance for both. We also chose to use opensource frameworks and tools, such as the Tomcat server runtime :
Start building Silverlight RIA in eclipse today !
With Eclipse4SL M2 plus the guidance to connect Java business logic, you can now build Silverlight applications in what we call the Pure Eclipse configuration or you may complement your design by using Expression Blend, and collaborate with .Net teams using Visual Studio.
If the XAML experience is now completed, it is fair to say that the C# development experience is still rudimentary (no code assist and no debug). Therefore, in real world, you’ll still need Visual Studio for the Silverlight C# code development and debug tasks (Hopefully, Visual Studio Web Express is free).
Improving the C# experience as well as supporting other dev platforms is still on the Eclipse4SL roadmap… stay tuned…
If you want to support this project, feel free to vote on EPIC, but also contact the Eclipse4Sl Team if you want to appear among the SLDT proposal interested parties.
- PDC2008 : Silverlight on its way to address Business Apps
-
Last week at PDC 2008, Jamie Cool demonstrated some very cool work under progress at Microsoft, to deliver a first class development experience for people looking forward to build Business Applications on top of Silverlight.
If you started working on business apps, you miss several capabilities with the current version of Silverlight : see yellow boxes below. This slides comes from Jamie Cool talk available on channel 9.
The availability of Jamie's framework has not been disclosed. If you cannot wait for those bits, have a look at CSLA.Net for Silverlight and here also. CSLA is already available. I did not have the opportunity to play with it yet.
A DPE Team from Switzerland wrote this synthesis of Jamie’s talk :
What this framework will give you are:
- “Shared Business Entities” between tiers that enable client side change tracking (using DiffGrams). Enabling optimistic locking multi records CRUD operations. Validation is also given thanks that the “Entities” can have attributes like [Range(0,100)] for end to end across tiers validation. You can also have a server side method for validation that gets triggered on update for example. All this can run on top of LINQ to SQL, the Entity Framework or even your custom DAL.
- A DataSource control is also provided and it can manage round trip to the server for efficient data paging, filtering and sorting. Basically it uses the IQuerable interface to filter, apply skip/take and order by on the server and the data round trip .
- Wrapper around the Authentication & Membership provider of ASP.NET are also provided. Including SL controls that enable you, with 2 line of code, to add Login functionality directly in Silverlight. It is also populating the Principal object in SL with the authenticated User, making it easier to use the identity in your UI tier. Last but not least you can decorate your server side “Entity” with permissions attributes to enable role base security on top of your “Entity” and CRUD operations.
- Page Navigation model including browser history integration. This make very easy to write multi forms application in SL. It plugs-in to the browser history, enabling user to navigate through the forms with the forward and backwards buttons, without reloading the SL application. It also enable the user to copy and paste around a Url, that will bring the user right back to the right form.
- Additional controls like form control to make even more productive data driven app development will be also provided.
- Architecture Series – Pure and Mixed configurations
-
This is the first article in an Architecture Series dealing with technical options taken for the Eclipse Tools for Silverlight. Future articles will focus on the XAML rendering architecture, the Eclipse extension points as well as the “MSBuild” project structure preservation option that was taken to allow the back and forth loop.
In the very first words of the eclipse4SL installation, you are told to choose between two configurations : Pure or Mixed Eclipse. Why that ? To minimize the size of the bits to download but also to adapt to your interoperability scenario (any co-workers using Microsoft Tools ?). So what ? That’s enough information to you. Fine, have fun with the Tutorials and please give your feedback. Now let’s talk about the Silverlight 2 runtimes, SDK and Tools for Visual Studio, and how they fit one with another.
If you’re new to Silverlight, you’ll want to begin with the Get Started section of the Silverlight site. After that take an hour or two to go through Scott Guthrie’s tutorials. Finally give a try to Tim Heuer’s technically amazing posts. BTW, have you read the Silverlight 2 announcements from Scott and Tim.
OK let’s start. From the Silverlight Tools page, you’ll notice that Silverlight 2 is composed of a runtime but also a set of development tools (developer runtime, SDK and Visual Studio Tools). Note that eclipse4SL has been added to the list of tools :-).
eclipse4SL uses several pieces of the Silverlight Tools to perform the compilation of your XAML code (you don’t know about XAML, experience it from the HelloWorld tutorial) : MSBuild version 3.5, complementary compilation tasks which come with the SDK and the Silverlight runtime to actually render the bits on the surface as well as run your application.
In a pure Microsoft environment, you would get the following configuration :
If you chose to install a Pure Eclipse configuration, the Silverlight runtime plus the Silverlight SDK are sufficient (the latter has a dependency on MSBuild 3.5 which comes with .Net 3.5). Note that .Net 3.5 SP1 is optional here. Bonus : as eclipse4SL M1 does not support debugging, you may use a standard Silverlight runtime instead of the developer runtime.
Finally, in a Mixed Eclipse configuration, you’ll go back and forth between Eclipse, Visual Studio and Expression Blend but this comes with a maximum of products to install.
Any comments, please use the forums.
- Eclipse Tools for Microsoft Silverlight
-
Silverlight 2 is Released to Web (RTW). This is great news for our RIA scenarios. But wait, there’s more.
Microsoft announced the launch of the Eclipse Tools for Microsoft Silverlight (eclipse4SL.org): an opensource project lead by Soyatec and funded by Microsoft. Here is what the eclipse4SL Team Blog states :
The purpose of this project is the creation of open source tools integrated with the Eclipse development platform that enable Java developers to use the Eclipse platform to create applications that run on the Microsoft Silverlight runtime platform. Specifically, the project will be an Eclipse plug-in that works with the Eclipse Integrated Development Environment (IDE) and Eclipse Rich Client Platform (RCP) to provide both a Silverlight development environment and greater interoperability between Silverlight and Java, to facilitate the integration of Silverlight-based applications into Java-based web sites and services.
I am thrilled to be part of this initiative we incubated at Microsoft France, working in collaboration with Vijay Rajagopalan (Microsoft Corp Interop Teams) and Yves Yang (Soyatec CEO). We brought interoperability to the next level here : France, United States, India and China :-).
One important point I want to highlight : eclipse4SL provides a full Silverlight experience for Eclipse developpers, but it can also be a great tool if you plan to work in an heterogeneous Java and .Net environment. From the beginning, we worked on an Architecture which preserves the MSBUILD .Net format, so that you can go back and forth from Visual Studio to Eclipse and Eclipse to Visual Studio, but also from Expression Blend to Eclipse and Eclipse to Expression Blend. This approach is referenced as Mixed configuration in the installation guide.
This preview release (named M1) will be out on Tuesday the 14th. It is the opportunity for the community to give its feedback so that we can adapt the project long term plans.
To ensure the best experience in your evaluation, eclipse4SL comes with 20 minutes Tutorials. Moreover, we selected a limited group of alpha testers including the French Java & opensource community from Application-Servers.com. Feedbacks are great.
"I think this is a great job. I look forward to experiment with advanced Silverlight Controls as well as its Web Services communication capabilities." Bruno Paul, Architect at ATOS Origin.
UPDATE : The eclipse Foundation has published the SLDT Project Proposal to turn eclipse4SL into an open source project under the Eclipse Development Process, on the 13th of october which they consider as Interesting Times Indeed…
“… this project proposes to extend the Silverlight Development Experience to all Web Application Developers should they be running Windows, Linux or Mac OS. The Silverlight Development Toolkit (SLDT) is a proposed open-source project under the Eclipse Development Process, and will incubate under the top-level Technology project.
Finally, I’d like to point out the determination of Microsoft’s top management and sponsors about the project (Sam Ramji, Jean Paoli, Scott Guthrie and S. Somasegar) who share a strong commitment towards interoperability.
- eclipse4SL : “DataGrid” Tutorial
-
Duration
20 minutes
Description
This tutorial demonstrates how to populate a DataGrid with dynamic data. When you press the Load Button, the DataGrid will be filled in, and eventually filtered if a filter has been specified. A pdf version of this tutorial is attached at the end of this post and accessible here.

Prerequisites
After installing eclipse4SL, you should have activated the Silverlight perspective by selecting one of them from the menu Window > Open Perspective > Other…. (for a detailed procedure, read the Hello World Tutorial).
Creating the Silverlight User Interface
We'll start by selecting the File->New menu item within Eclipse and use the eclipse4SL Silverlight Project menu to create a "Silverlight Web Project" , named DataGridTutorial.

Open the Page.xaml control, remove the Grid component.
Drag and drop the StackPanel container from the Palette, and add 4 components inside by drag and drop too :
- a TextBock which Text value is “Filter :”
- a TextBox which Text value is empty
- a Button which Content value is “Load”
- and our DataGrid which Width and Height are 380 and 230 respectively
<UserControl x:Class="DataGridTutorial.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300"
xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<StackPanel>
<TextBlock Text="Filter :"></TextBlock>
<TextBox Text="" />
<Button Content="Load"></Button>
<Controls:DataGrid Width="380" Height="230"></Controls:DataGrid>
</StackPanel>
</UserControl>
Notice that as you have dropped a DataGrid on to the XAML code, a reference to the assembly containing the component is automatically added to the Silverlight project (System.Windows.Controls.Data). The following XAML rendering is displayed :

To obtain the arrangement and look & feel proposed at the beginning of the document, use a Canvas, and specific positions for the different components. Replace the StackPanel and its contents by the following XAML :
<UserControl x:Class="DataGridTutorial.Page"
xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400"
Height="300">
<Canvas x:Name="LayoutRoot" Background="Azure">
<TextBlock Text="Filter :"
Canvas.Left="10" Canvas.Top="15" Width="100"></TextBlock>
<TextBox Text=""
Canvas.Left="60" Canvas.Top="10" Width="100"></TextBox>
<Button Content="Load"
Canvas.Left="180" Canvas.Top="11" Width="50"></Button>
<my:DataGrid
Canvas.Left="10" Canvas.Top="50" Width="380" Height="230"
RowBackground="Aquamarine"
AlternatingRowBackground="White"></my:DataGrid>
</Canvas>
</UserControl>

Let’s run the project, by creating a Run Configuration for our project as described in the HelloWorld Tutorial.

Adding behavior to the User Interface
Now, let’s assign names to the Filter and our DataGrid so that we can access them from our C# code behind. Add the property x:Name=”country” to the TextBox and x:Name=“grid” to our DataGrid. Moreover, we’ll add the AutoGenerateColumns property to the DataGrid so that it automatically adapts to the data source it is connected to.
<UserControl x:Class="DataGridTutorial.Page"
xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400"
Height="300">
<Canvas x:Name="LayoutRoot" Background="Azure">
<TextBlock Text="Filter :"
Canvas.Left="10" Canvas.Top="15" Width="100"></TextBlock>
<TextBox Text="" x:Name="country"
Canvas.Left="60" Canvas.Top="10" Width="100"></TextBox>
<Button Content="Load"
Canvas.Left="180" Canvas.Top="11" Width="50"></Button>
<my:DataGrid x:Name="grid" AutoGenerateColumns="True"
Canvas.Left="10" Canvas.Top="50" Width="380" Height="230"
RowBackground="Aquamarine"
AlternatingRowBackground="White"></my:DataGrid>
</Canvas>
</UserControl>
Finally, we’ll add an event handler to the Click event on the button. Position your cursor right after the Content of the Button, and press CTRL – SpaceBar for Code Content Assist.

Select the Click event. After a second, a wizard is displayed that let you specify the name of the C# code behind associated with the button Click action.

Name it Button_Click and confirm. You are automatically directed to the code behind file Page.xaml.cs.
Let’s affect a static list to our DataGrid by setting its ItemsSource.
Copy and paste the following code :
using ...;
namespace DataGridTutorial
{
public partial class Page : UserControl
{
/**
* Event handler of <code>Button.Click</code>.
*/
private void Button_Click(object sender, RoutedEventArgs arg1) {
grid.ItemsSource = new string[] { "Eclipse Tools for Silverlight",
"is an open source project",
"delivered by SOYATEC",
"and funded by Microsoft" };
}
public Page()
{
InitializeComponent();
}
}
}
Run the application again, and press the Load Button.

Loading and filtering multi-dimensional data
The following code defines a Customer class composed of a Name, Company and a Country. After initializing an Array of Customers, we will filter it with the Filter if it has been specified.
Notice that we use the Linq technology to filter the contents (Silverlight 2 embeds the Linq to Object and Linq to XML frameworks). Replace the contents of Page.xaml.cs by the following code :
public partial class Page : UserControl
{
// Internal Class
public class Customer
{
public string ContactName { get; set; }
public string Company { get; set; }
public string Country { get; set; }
public Customer() { }
}
// Initialize list of customers to display in the Grid
Customer[] customers = new Customer[] {
new Customer { ContactName = "Stève Sfartz", Company = "Microsoft", Country = "France" },
new Customer { ContactName = "Vijay Rajagopalan", Company = "Microsoft", Country = "United States" },
new Customer { ContactName = "Yves Yang", Company = "Soyatec", Country = "France" }
};
public Page()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// Retreive Filter set in the Silverlight UI
string filter = country.Text.Trim();
// Display filtered results in Grid if the filter is not empty
if (String.IsNullOrEmpty(filter)) {
grid.ItemsSource = customers;
}
else {
// Filter
var selection = from c in customers where c.Country == filter select c;
// Display in Grid
grid.ItemsSource = selection.ToArray<Customer>();
}
}
}
Run the project and click the Load Button.

Enter France as a Filter and Click on the Load Button again

Author
Steve SFARTZ works for Microsoft France as an Architect Evangelist, with expertise in Enterprise Architecture, Interoperability, SOA & Cloud Computing.
You’ll find further guidance about Silverlight & Java interoperability on A Cup of Silverlight.
If you can read french, you may check one of my other blogs : Think Big mais pas trop..., SOA & Interop @Microsoft France, Cloud Computing @ Microsoft France.
- eclipse4SL : “Hello World” Tutorial
-
Duration
30 minutes
Description
This tutorial is inspired from Scott Guthrie Silverlight 2 Series, adapted from Visual Studio to the eclipse4SL environment. A pdf version of the tutorial is attached at the end of this post and accessible here.
Prerequisites
After installing eclipse4SL, activate the Silverlight perspective by selecting one of them from the menu Window > Open Perspective > Other….

Note : eclipse4SL proposes 2 perspectives :
· Eclipse style : the project explorer is docked on the left, the palette is docked on the right
· Visual Studio style : it is the opposite.

Creating a New Silverlight Application using eclipse4SL
We'll start by selecting the File->New menu item within Eclipse and use the New Silverlight Project menu to create a "Silverlight Web Project" :
![clip_image004[7] clip_image004[7]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image004%5B7%5D_thumb.jpg)
First time through you need to click other and scroll down to the Silverlight folder.
![clip_image006[7] clip_image006[7]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image006%5B7%5D_thumb.jpg)
Note : eclipse4SL proposes 2 types of Silverlight projects :
· the “Silverlight Project” should be used to create Silverlight Application (ie, it does not comprise a Web Site which hosts the Silverlight application),
· whereas the “Silverlight Web Project” option comprises 2 Eclipse projects : one which holds the Silverlight Application while the second one is the Web application which hosts the Silverlight code.
We'll name the project "Hello World Tutorial".
![clip_image008[7] clip_image008[7]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image008%5B7%5D_thumb.jpg)
When we click the "Finish" button, eclipse4SL will create two related projects :
· a Silverlight client application (HelloWorldTutorial)
· and a Web application (HelloWorldTutorial.Web).
![clip_image010[6] clip_image010[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image010%5B6%5D_thumb.jpg)
Note : Both projects conform to the standard Silverlight project hierarchy tied by the .NET Build command. This architecture allows us to switch back and forth between Eclipse, Visual Studio and Expression Blend. This is a important characteristic of eclipse4SL that make it easier to work in a Mixed environment.
Let’s run the application right away to get an instant Microsoft Silverlight touch J
From the Eclipse Run options, select “Run Configurations...”. In the Snapshot below, no configuration pre-exists (no launch history).
![clip_image012[6] clip_image012[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image012%5B6%5D_thumb.jpg)
Select "Silverlight Web App" and create a new Launch Configuration by clicking the
icon at the top left, name the configuration HelloWorldTutorial, and select the HelloWorldTutorialTestPage.html from the HelloWorldTutorial.Web project as the Start page.
![clip_image016[6] clip_image016[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image016%5B6%5D_thumb.jpg)
Click Apply and Run…
A browser window opens and displays an empty screen. The snapshot shows Internet Explorer and FireFox since both are supported on Windows. In the next section, we’ll add components to the user interface, so far, it’s empty. Notice that if you right-click on the blank surface, the Silverlight runtime menu is displayed.
![clip_image018[6] clip_image018[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image018%5B6%5D_thumb.jpg)
![clip_image020[6] clip_image020[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image020%5B6%5D_thumb.jpg)
Note: Silverlight Applications can be used with any web-server (should it be IIS or Tomcat on Windows,or Tomcat on Mac or Linux) and hosted within static HTML files or any server-side generated page (including .Net, PHP, Java, Python, Ruby, etc). For this HelloWorld tutorial we won't be writing any server-side code.
Understanding What Is In a Silverlight Application
By default a newly created Silverlight application project contains a Page.xaml and App.xaml file, as well as code behind class files (which can be written in VB, C#, Ruby or Python) that are associated with them:
![clip_image022[6] clip_image022[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image022%5B6%5D_thumb.jpg)
XAML files are XML text files that can be used to declaratively specify the UI of a Silverlight or WPF application (Windows Presentation Foundation that is the Rich Desktop technology corresponding to Silverlight in the Browser). XAML can also be used more broadly to declaratively represent .NET objects (Workflows..)
The App.xaml file is typically used to declare resources, such as brush and style objects that are shared across the application. The Application code-behind class for the App.xaml file can be used to handle application level events - like Application_Startup, Application_Exit and Application_UnhandledException.
The Page.xaml file is by default the initial UI control that is loaded when the application activates. Within it we can use UI controls to define our user interface, and then handle events off of them within the Page code-behind class.
When we build our HelloWorld project, Eclipse will by default compile the code and .XAML markup into a standard .NET assembly file, and then package it and any static resources (like images or static files we want to include in it) into a " HelloWorld.xap" file on disk :
![clip_image024[6] clip_image024[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image024%5B6%5D_thumb.jpg)
".xap" files (pronounced "zap") use the standard .zip compression algorithm to minimize client download size. Our "Hello World" Silverlight application should be about 4KB in size (in fact it is 130 Ko in M1, see below).
Note : Some controls are implemented in assemblies that if used are redistributed in the application's .xap file (which will increase an application's size above the 4kb base size). All of the controls used in the HelloWorld application are in the core Silverlight 2 runtime - which means that the total download size of the finished application will probably only be in the 6-8kb range (so very small and fast).
The October 2008 community preview (M1) of eclipse4SL embeds a set of extended controls (contained in the System.Windows.Controls.Data.dll library). The eclipse4SL dev team had to take this extreme shortcut to deliver on time. This will be fixed for M2.
To host and run a Silverlight 2 application, you can add an <object> tag into any standard HTML page (no JavaScript required) that points to the .xap file. Silverlight will then automatically download the .xap file, instantiate it, and host it within that HTML page in the browser. This works cross browser (Safari, FireFox, IE, etc) and cross platform (Windows, Mac, and Linux).
Learning how to Add Controls and Handle Events
Right now our Hello World application doesn't do anything, and when it is run it brings up an empty page.
We can change this by opening up the Page.xaml file in the project and adding some content to it, by dragging the “Button” from the eclipse4SL Palette to the Page.xaml source XML code.
Note : Drag & Drop onto the rendering surface is not implemented. You should drag the UIElement to the XAML code area.
![clip_image026[6] clip_image026[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image026%5B6%5D_thumb.jpg)
We'll begin by changing the background of the grid and by declaring a Button control within it. We'll give the button an "x:Name" attribute value of "MyButton" - which will allow us to programmatically reference it within our code-behind class. We'll also set its Content, Width and Height properties:
<Button x:Name="MyButton" Content="Push Me !" Width="100" Height="50" />
Note: Html tags Content, Width and Height are case sensitive. If you write height or width instead, you’ll get a 100% progress bar at run time and a blank screen but no further warning.
![clip_image028[6] clip_image028[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image028%5B6%5D_thumb.jpg)
When we run the application our button will then show up in the middle of the page with "Push Me" content text like below:
![clip_image030[6] clip_image030[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image030%5B6%5D_thumb.jpg)
To add behavior to our button we can add a "Click" event handler to it. We can do this in source view by typing the event name “Cl...” and using Code Completion (Ctrl + Space Bar).
![clip_image032[6] clip_image032[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image032%5B6%5D_thumb.jpg)
Choose the Click event. Then a wizard is displayed to assist in the delegate method development.
![clip_image034[6] clip_image034[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image034%5B6%5D_thumb.jpg)
We can then either type a new event handler method name to use, or optionally use the default naming convention :
![clip_image036[6] clip_image036[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image036%5B6%5D_thumb.jpg)
eclipse4SL will then automatically create a stub event handler implementation in our code-behind class file.
We can use this event handler to update the Button's content with a new message when it is clicked:
/**
* Event handler of <code>ButtonClick</code>.
*/
private void ButtonClick(object sender, RoutedEventArgs arg1) {
MyButton.Content = "Pushed";
}
![clip_image038[6] clip_image038[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image038%5B6%5D_thumb.jpg)
After making the change above we can re-run the application and push the button again, and now its content is updated with a "Pushed!" message:
![clip_image040[6] clip_image040[6]](http://blogs.msdn.com/blogfiles/silverlight_plus_java/WindowsLiveWriter/eclipse4SLHelloWorldTutorial_EBB/clip_image040%5B6%5D_thumb.jpg)
Next Steps
We still have a little more work left to-do before our application is done... :-)
Our next step will be to setup the overall UI layout structure of our application, and arrange more controls within it. Using layout management. This article from Scott Guthrie has not be ported yet to eclipse4SL. If you wish to contribute, this is your opportunity.
Author
Steve SFARTZ works for Microsoft France as an Architect Evangelist with expertise in Enterprise Architecture, Interoperability, SOA & Cloud Computing.
You’ll find further guidance about Silverlight & Java interoperability on A Cup of Silverlight.
If you can read french, you may check one of my other blogs : Think Big mais pas trop..., SOA & Interop @Microsoft France, Cloud Computing @ Microsoft France
- Tip : Add XAP Mime-Type in Tomcat and IIS 5.1
-
Mime-Type are used to provide identifiers for file formats on the Internet.
By default, XAP files are not recognized as a Silverlight application in Tomcat or IIS 5.1. You can set a Mime-Type to identify XAP files on both servers.
Setting Mime-Type in Tomcat
in %TOMCAT_INSTALL%/conf directory, edit web.xml file. Add the following description to identify XAP files
<mime-mapping>
<extension>xap</extension>
<mime-type>application/x-silverlight-2-b2</mime-type>
</mime-mapping>
- Restart Tomcat and clear your navigator cache,
- get a XAP file to ensure that the Mime-Type is correctly set
Setting Mime-Type in IIS 5.1
- Open the IIS Management Console
- Open your Web Site properties, under HTTP Headers click on File Types button
- In the File Types window, click New Type to add a new Mime-Type
- Get a XAP file within IIS to ensure that the Mime-Type is correctly set
- Ronny Kwon
- How-To : Silverlight accessing Java SOAP services (Part 2 – No Cross Domain : Tomcat/Eclipse)
-
The HowTo series demo Silverlight accessing Web Services in various configuration. In this post, we will demonstrate you a SOAP service consumed by a Silverlight client application where the Site of Origin hosts the Web Services. This scenario is categorized as a D2D scenario without cross-domain policy.
The SOAP service Eclipse project and the Silverlight Eclipse project are available as an attachment to this post.
Technical Environment
- SOAP services are built with the JAX-WS and JAX-B Api and hosted in Tomcat
- The Silverlight application is also hosted in Tomcat
Because the Site of Origin and the Web Service reside in the same host, no Cross Domain policy is required.
Hosting the Web Service in Tomcat
In case you haven’t done the How-To : Silverlight accessing Java SOAP services (Part 1 – Cross Domain : IIS + Tomcat), you can directly import the SOAP-Sum service Eclipse project into your Eclipse Workspace.
Hosting the Silverlight Application using a Servlet
In the REST way, we showed you how to host a Silverlight Application using a JSP. Now we are going to host a Silverlight application using a Servlet
- In Eclipse, create a new dynamic web project named Silverlight-SOAP-SumService_NOSSL
- In WebContent folder, add a folder named ClientBin and copy in the latter, the xap file in the attachment. The Silverlight Application is already configured to access the SOAP service at http://localhost:8080/SOAP-SumService/services/sum?wsdl.
- Add a Servlet named SilverlightServlet to a package ‘servlet’ and add the following code :
Instance of Silverlight plugin :
private void responseHandler(HttpServletResponse response) throws IOException{ PrintWriter pw = response.getWriter();
pw.println("" + "<div id=\"silverlightControlHost\">" +
" <object data=\"data:application/x-silverlight,\"" +
" type=\"application/x-silverlight-2-b2\"" +
" width=\"100%\" height=\"100%\">" +
" <param name=\"source\" value=\"ClientBin/SOAP-Sum.xap\"/>" +
" <param name=\"background\" value=\"white\" />" +
" <a href=\"http://go.microsoft.com/fwlink/?LinkID=115261\"" +
" style=\'text-decoration: none;\'>' +
" <img src=\"http://go.microsoft.com/fwlink/?LinkId=108181\""+
" alt=\"Get Microsoft Silverlight\"" +
" style=\'border-style: none\'/>' +
" </a>" +
" </object>" +
" <iframe style='visibility:hidden;height:0;width:0;border:0px'>' +
"</iframe>" +
"</div>");
pw.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { responseHandler(response);
super.doGet(request, response);
}
Silverlight will access the SOAP-Sum service without cross-domain
- Ronny Kwon
- Tip : Serving JSPs and Servlets from IIS through Tomcat
-
This tip is about making IIS as a front end to Tomcat hosting Servlets and JSPs on the back end. This architecture allows the hosting of JAX-WS or Restlet services in Tomcat while Silverlight clients are hosted in IIS without facing cross-domain issues.
The configuration files and the connector (isapi_redirect.dll) are available as an attachment to this post. Before continuing, you must download the Zip archive and unzip it to C:\Program Files\Apache Software Foundation
The following is inspired from
The Apache Tomcat Connector - Webserver HowTo : IIS HowTo
Pre-requisites
From this point, we assume that
- IIS 5.1 is installed on a Windows XP SP2 Professional Edition
- Apache Tomcat 6.0.16 is installed and working properly on the same OS
- The Tomcat installation directory is C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16
- You have unzipped the archive, you must have the following directory : C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector
Configuring the ISAPI Redirector
- Open the Registry Editor, Run—>regedit
Create a new registry key names “HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0”
- The following screenshot shows you the different values you have to create in the previous created key
| name |
value |
| extension_uri |
/jakarta/isapi_redirect.dll |
| log_file |
C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector\log\isapi_redirect.log |
| log_level |
info |
| worker_file |
C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector\conf\workers.properties.minimal |
| worker_mount_file |
C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector\conf\uriworkermap.properties |
- Alias must be set to “jakarta”
- Directory must be set to isapi_redirector.dll location C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector\bin
- Allow Execute permission
Now let’s add a new ISAPI filter
- open the properties dialog of the Default Web Site, in the ISAPI Filters tab, click add to add a new filter.
- Set the filter name to “jakarta”
- Executable is the exact location of the isapi_redirect.dll : C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector\bin\isapi_redirect.dll
- Restart the IIS Server then check for the jakarta filter, an up-green arrow has appeared
Also start Tomcat server.
In a Web Browser, ensure that http://localhost:8080/examples/jsp/index.html is accessible :
It’s normal, this page is served by Tomcat (assuming that it is running on port 8080)
Now access to this page within IIS (in our case, we set IIS port to 81), by default port 80 is used.
Go to http://localhost:81/examples/jsp/index.html. A similar page is displayed.
Try to execute a jsp example :
Configuring the URL mapping
In the C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector\conf directory you will find two configuration files :
In the uriworkermap.properties you will find the mapping of URL to be handled by the workers declared in workers.properties. An example of URL mapping:
default.worker=ajp13
/docs=$(default.worker)
/docs/*=$(default.worker)
/examples=$(default.worker)
/examples/*=$(default.worker)
/host-manager=$(default.worker)
/host-manager/*=$(default.worker)
/manager=$(default.worker)
/manager/*=$(default.worker)
In this configuration, every request on /examples/* will be handled by the Tomcat process, that’s how we managed to serve JSPs and Servlets from IIS through Tomcat. You may add your own URL patterns... if you do so, don’t forget to restart the Tomcat Server.
- Ronny Kwon
- Tip : Cross Domain Policy when Self-Hosting your Services
-
This tip is about self hosting of services with the .Net WCF or Java Restlet framework. Cross-domain access is mandatory here since the Site of Origin does not host the services.
Self hosting a service represents a quick & easy way to expose a Web Service for tests purpose. Yet, customization is extermely limited since self hosting does not provide you all the capabilities of Web Servers such as delivering static content (cross domain policy file).
The first thing you need to know is that when Silverlight attempts to access services in cross-domain, it will send a HTTP GET method on http://<domain:port>/clientaccesspolicy.xml or http://<domain:port>/crossdomain.xml (in case clientaccesspolicy.xml wasn’t found). If you plan to self host your Web Service, you will agree that there is no possible way to host a physical Cross Domain policy file at the root of the Web Server.
You must handle this request through your Service implementation. It usually matches the /clientaccesspolicy.xml or /crossdomain.xml URI pattern.
WCF way (inspired from Carlo’s blog)
Self-hosted Service
class Program
{ static void Main(string[] args)
{ // URI of the Service
Uri uri = new Uri("http://localhost:8081/");
// create a new WebServiceHost specifying the implementation of the Service
// and the specified uri to bind with
WebServiceHost host = new WebServiceHost(
new REST_ItemsServiceLibrary.ItemsREST(),
uri);
// add the Service Endpoint specifying the Service Interface
host.AddServiceEndpoint(typeof(REST_ItemsServiceLibrary.IItemsREST),
new WebHttpBinding(), "");
// open the WebServiceHost
host.Open();
Console.WriteLine("Service hosted at {0}", uri.OriginalString); Console.ReadLine();
// close the WebServiceHost
host.Close();
}
}
Handling cross-domain file requests
As we said earlier, we have to manage the /clientaccesspolicy.xml, specify in the Service Interface that HTTP GET method on the URI /clientaccesspolicy.xml will be handled by GetSilverlightPolicy();
[OperationContract]
[WebGet(UriTemplate ="/clientaccesspolicy.xml")]
Stream GetSilverlightPolicy();
this also applies to /crossdomain.xml
Finally, in your Service implementation, return a clientaccesspolicy.xml content:
public Stream GetSilverlightPolicy()
{ string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers=""*"">
<domain uri=""*""/>
</allow-from>
<grant-to>
<resource path=""/"" include-subpaths=""true""/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>";
return StringToStream(result);
}
Stream StringToStream(string result)
{ WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
return new MemoryStream(Encoding.UTF8.GetBytes(result));
}
Restlet way
Self-hosted Service
public static void main(String[] args) { try { // Create a new Component.
Component component = new Component();
// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);
// Attach the sample application.
component.getDefaultHost().attach(
new FirstResourceApplication(component.getContext()));
// Start the component.
component.start();
} catch (Exception e) { // Something is wrong.
e.printStackTrace();
}
}
Handling cross-domain file requests
Following the same philosophy as the WCF way, we need to handle HTTP GET method on /clientaccesspolicy.xml file request :
In the Application implementation you must bind the URI pattern with the Ressource that will handle it :
Finally, implement the ClientAccessPolicy class, specially the HTTP GET method within getRepresentation method :
package firstResource;
import java.io.IOException;
import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.DomRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.Variant;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class ClientAccessPolicy extends Resource{
public ClientAccessPolicy(Context context, Request request,
Response response) { super(context, request, response);
getVariants().add(new Variant(MediaType.TEXT_XML));
}
@Override
public Representation getRepresentation(Variant variant){ if (MediaType.TEXT_XML.equals(variant.getMediaType())) { try { DomRepresentation representation = new DomRepresentation(
MediaType.TEXT_XML);
// Generate a DOM document representing the list of
// items.
Document d = representation.getDocument();
Element accesspolicy = d.createElement("access-policy"); d.appendChild(accesspolicy);
Element crossdomainaccess = d.createElement("cross-domain-access"); accesspolicy.appendChild(crossdomainaccess);
Element policy = d.createElement("policy"); crossdomainaccess.appendChild(policy);
Element allowfrom = d.createElement("allow-from"); allowfrom.setAttribute("http-request-headers","*");
Element domain = d.createElement("domain"); domain.setAttribute("uri", "*");
allowfrom.appendChild(domain);
Element grantto = d.createElement("grant-to"); Element resource = d.createElement("resource"); resource.setAttribute("include-subpaths","true"); resource.setAttribute("path", "/");
grantto.appendChild(resource);
policy.appendChild(allowfrom);
policy.appendChild(grantto);
d.normalizeDocument();
// Returns the XML representation of this document.
return representation;
} catch (IOException e) { e.printStackTrace();
}
}
return null;
}
}
- Ronny Kwon
- How-To : Silverlight accessing Java REST services (Part 2 – No Cross Domain : Tomcat/Eclipse)
-
The HowTo serie demoes Silverlight accessing Web Services in various configuration. In this post, we will demonstrate a REST service consumed by a Silverlight client application where the Site of Origin hosts the Web Services. This scenario is categorized as a D2D scenario without cross-domain policy.
The XAP package, the REST service Eclipse project and the Silverlight Eclipse project are available as an attachment to this post.
Technical Environment
- REST services are built with the Restlet framework and hosted in Tomcat
- The Silverlight application is also hosted in Tomcat
Because the Site Of Origin and the Web Services reside in the same host, no Cross Domain policy is required.
To successfully install the technical environment, please take the following step :
If you don’t feel like doing the previous step, the XAP package available as an attachment contains a Silverlight client which is configured to access a REST service at http://localhost:8080/Restlet-servletfirstResource/items.
The REST service is also available as an attachment to this post allows to do a GET and POST method to get a list of items or to insert a new one.
Download the attachment and unzip it. There are two needed parts : the Silverlight XAP package and the Restlet Eclipse project.
Host the REST service with Tomcat
- Import the Reslet-servletfirstResource project into your Eclipse workspace :
- go to File –> Import
- Then chose General—>Existing Projects into Workspace
- Select the root directory, Browse to the Restlet-servletfirstResource folder, then click on Finish. The Restlet-servletfirstResource has now been imported into your workspace
- Run the project on Tomcat Server. check that http://localhost:8080/Restlet-servletfirstResource/items is accessible you should get the following result :
Host the Silverlight application in an Eclipse project running on Tomcat
- Create a new Dynamic Web Project
- Press Ctrl+n to go to the New Wizard Project, under Web select Dynamic Web Project.
- Call it REST-SilverlightClient and ensure that the Target Runtime is set to Apache Tomcat 6.0
- If Eclipse prompts you to switch to J2EE perspective, accept it.
- In the REST-SilverlightClient project, create the WebContent\ClientBin folder and copy the XAP package into it.
- Now we need to host it through an Active X control :
- Right click on WebContent folder and select New—>JSP, call it index
- Edit index.jsp, in the Head part put the following script that catches Silverlight Error.
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) { appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n" ;
errMsg += "Code: "+ iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError")
{ errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError")
{ if (args.lineNumber != 0)
{ errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
- In the Body part, instantiate a Silverlight control by adding the following HTML code, ensure that the param named “source” has is value set to the XAP package URI relative to index.jsp Web Page:
<div id="silverlightControlHost">
<object data="data:application/x-silverlight,"
type="application/x-silverlight-2-b2"
width="100%" height="100%">
<param name="source" value="ClientBin/REST-JavaServiceItem.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<a href="http://go.microsoft.com/fwlink/?LinkID=115261"
style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181"
alt="Get Microsoft Silverlight"
style="border-style: none"/>
</a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
- Run the project on Tomcat Server and the Silverlight control will appear in the Eclipse Web Browser :
The great thing about that is that you will be able to test your REST Service and the Silverlight application without running multiple Development Environments.
- Ronny Kwon
- How-To : Silverlight accessing Java SOAP services (Part 1 – Cross Domain : IIS + Tomcat)
-
The How-To series demo Silverlight accessing Web Services in various configuration. In this post, we will demonstrate a SOAP service consumed by a Silverlight client application. This scenario can be categorized as a D2D scenario with a cross domain policy.
Both the Silverlight and SOAP service are available as an attachment to this post. Since Metro libraries are too large, you will need to copy all jar files from metro\lib\ folder into WebContent\WEB-INF\lib project folder. Steps are described below.
Technical environment
- SOAP services are built with JAX-WS and JAX-B APIs and hosted in Tomcat.
- The Silverlight application is hosted under the Visual Studio embedded Web Server code name “Catalina” (which delivers a subset of the IIS capabilities)
Requirement
For this How-To, we use the Metro framework which contains both JAX-WS and JAX-B APIs which will be used to develop SOAP Services in JAVA.
Configuring Tomcat
Download the jar file from https://metro.dev.java.net/1.2/ and launch it. A “metro” folder has been created at the jar location. metro\lib folder contains all the needed libraries for the Java SOAP service development and Tomcat configuration. Here is a good link that describes how to configure your Tomcat server http://blogs.sun.com/arungupta/entry/metro_on_tomcat_6_x
Implementing the SOAP / RPC service
- In Eclipse, create a new Dynamic Web Project called “SOAP-SumService”
- copy all jar files from metro\lib\ folder into WebContent\WEB-INF\lib project folder.
- Create a package called “service” and add a new Java class called “ServiceSumImpl” to this package.
- Add a xml file to WebContent\WEB-INF called “sun-jaxws.xml”.
Your project structure now looks like this :
Implementation of the Web Service endpoint
In ServiceSumImpl.java, import the following libraries :
Declare the class as a Web Service endpoint with the following annotations, for more informations about annotations refer to this site.
The only method that our service exposes is getSum. It returns the sum of two integers. But we want this method to be known over the service as “SumTwoInt”. Within the annotations we can configure all these parameters.
- Now build the project to generate the bytecode as the WSGen tool need it.
Generation of the required artifacts for the Web Service deployment and invocation
For this step, Metro provides a generation tool called “wsgen”.
- Open a Windows Command Prompt : Start->Run and type “cmd”
- set a METRO as a path variable to metro\bin folder (in our case it is C:\metro\bin path)
- Go to your build project folder (by default in Eclipse: ProjectName\build\classes). In our example it is the SOAP-SumService\build\classes folder
Type the following command line to generates the artifacts in the project “src” folder.
%METRO%\wsgen –cp . service.ServiceSumImpl –s ../../src
- Refresh the Project Explorer and observes that two java files have been generated
They represent the message that will be shared in the Web Service process
Configuring the Web Service Deployment
To configure the deployment, we need to instantiate a Servlet that will handles JAX-WS Web Services requests.
In web.xml, add a Servlet element. We use a pre-existing Web Service Servlet :
<servlet>
<servlet-name>jaxservlet</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
This servlet will handle every requests on /services/* URI, so let’s map to it with its name:
<servlet-mapping>
<servlet-name>jaxservlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
To provide the right context, we need a listener (which also already exists):
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
Finally, we need to expose the endpoint ServiceSumImpl within an URI, for example /services/sum.
Edit the sun-jaxws.xml file and add the following elements :
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint
name="sum"
implementation="service.ServiceSumImpl"
url-pattern="/services/sum"/>
</endpoints>
- Save all files, then Run the project on the Tomcat Server
Right click on the project node : Run As –> Run on Server
The service is now hosted on Tomcat at http://localhost:8080/SOAP-SumService/services/sum?wsdl

Enabling Cross Domain Access
Since the SOAP service and the Silverlight application reside on different hosts, we need to overpass the Cross Domain Issue. Create at the root of the SOAP service host, a clientaccesspolicy.xml file with the following content :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Consuming a SOAP service with Silverlight
Now that the Web Service is exposed, we are going to generate the client proxy to consume the Web Service with Silverlight.
Open Visual Studio 2008 and create a new Silverlight Project called SOAP-Sum and paste the following XAML code in Page.xaml to obtain a simple interface that will manipulate the web service.
<UserControl x:Class="SOAP_Sum.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas x:Name="LayoutRoot" Background="White">
<TextBox Text="0" x:Name="_int1" Width="50" Height="20"
Canvas.Top="10" Canvas.Left="30" TextChanged="_TextChanged"/>
<TextBlock Canvas.Top="10" Canvas.Left="95" Text="+"/>
<TextBox Text="0" x:Name="_int2" Width="50" Height="20"
Canvas.Top="10" Canvas.Left="120" TextChanged="_TextChanged"/>
<TextBlock Canvas.Top="10" Canvas.Left="175" Text="="/>
<TextBlock x:Name="_result" Canvas.Top="10" Canvas.Left="190" Text=""/>
</Canvas>
</UserControl>
- Add a Service Reference
Right click on References then chose Add a Service Reference
- In Address field, type the Sum service address then click Go (it should be http://localhost:8080/SOAP-SumService/services/sum?wsdl).
We actually have the Sum service named ServiceSum and one operation exposed as SumTwoInt, this is exactly what we did parameter in “Implementation of the Web Service endpoint” (see above)
- In Namespace field, type ServiceSum : this is how the service will be accessible through the Silverlight project. Click OK. In the Solution Explorer you see the ServiceSum reference in Service References.
Implementation of the client proxy
In Page.xaml.cs, add an import to SOAP-Sum.ServiceSum reference library.
1: using SOAP_Sum.ServiceSum;
Now we need to handle the TextChanged event in _TextChanged method :
- Instantiate a client proxy
ServiceSumClient client = new ServiceSumClient();
- Add an event handler corresponding to the operation we are going to use so we can get the result
client.SumTwoIntCompleted +=
new EventHandler<SumTwoIntCompletedEventArgs>
(
client_SumTwoIntCompleted
);
- Use Async operation to send our two integers.
Operations are made asynchronous so Silverlight UI won’t freeze
client.SumTwoIntAsync(a,b);
The whole method looks like this :
1: private void _TextChanged(object sender, TextChangedEventArgs e)
2: { 3: // check if fields contain some text
4: if (_int1.Text == "" || _int2.Text == "") return;
5:
6: int a = int.Parse(_int1.Text);
7: int b = int.Parse(_int2.Text);
8:
9: // generate a client proxy to the Web Service
10: ServiceSumClient client = new ServiceSumClient();
11: client.SumTwoIntCompleted += new EventHandler<SumTwoIntCompletedEventArgs>(client_SumTwoIntCompleted);
12: client.SumTwoIntAsync(a,b);
13: }
Then we can process the result in the event handler
void client_SumTwoIntCompleted(object sender, SumTwoIntCompletedEventArgs e)
{ _result.Text = e.Result.ToString();
}
Run the project and type some integers in the text boxes : Silverlight is consuming a JAX-WS SOAP service.
- Ronny Kwon
- B2C scenario : Customer Environement
-
The B2C scenario corresponds to Web applications accessed by customers, traditionnaly built with some dynamic HTML/AJAX technology running on the server side, that have been elected to leverage the Silverlight capabilities (enriched user experience, vector based contents, scaling, rich media…).To comply with the scope of this blog, we’ll concentrate on RIA scenarios, where the customer accesses private data from a Silverlight Client.
As listed in Silverlight scenarios for Rich Internet Applications, the following constraints apply to the Customer Environment scenario :
- Infrastructure security is mandatory : it includes a DMZ to protect the Web Server and access to the Web Services and optional SSL/HTTPS communications depending on the confidentiality of the data accessed.
- Protocol adaptation is required if the application is interfaced with pre-existing Web Services that cannot be immediatly consumed by Silverlight. This extract work is performed by a mediation layer, materialized in the schema below by the Services Gateway. Moreover, the Services Gateway in the Customer scenario can enforce the alignement of the incoming messages with the entreprise governance policies.
- Authentication & authorization is required for Line of Business Applications to secure read and write access to Entreprise Data. Form based authentication would be the preferred way in this scenario. If you need Claim based authentication, take a look at the B2B scenario.
- A cross domain security file is required to access the Services Gateway

We plan to document this scenario by extending the “B2E with mediation” scenario, with Form Based Authentication & Authorization constraints. If you have technical requirements not list here, there’s good chance the B2C scenario can be enriched from the B2B scenario.
- Cross Domain : Trouble while accessing Web Services
-
When Silverlight attempts to access a Web Service, if the SOO is different from the Web Service host, you have to deal with a cross domain issue. This issue can occur in various scenarios as described in Silverlight scenarios for Rich Internet Applications
The issue can be treated as follow :
1. I am encountering a ProtocolException
- Reason
Silverlight is attempting to access a Web Service which is across its own domain boundaries. For security reasons, a policy file must exist at the root of the Web Service host. It allows this cross-domain access : it’s either clientaccesspolicy.xml or crossdomain.xml files which were not found by Silverlight.
2. Even if the clientaccesspolicy.xml is found, my Silverlight application access the service
- Reason
Indeed, the clientaccesspolicy.xml file is here but is not accepted by the Silverlight application : there is some missing information.
There has been some modifications since Silverlight 2 beta 2 : Ensure that ‘http-request-headers’ attribute is correctly set in ‘allow-from’ element in the clientaccesspolicy.xml file. See below for a basic and working policy file :
<?xml version="1.0" encoding="UTF-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
More information can be found at
http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx
- Ronny Kwon