Home >
Service Communications with Silverlight
I get asked a lot about how the different ways there are to communicate from Silverlight applications to other sources through web services. Choosing the right means of communication is important and the best choice often depends on what the need is. A few of the options are:
- Talk to a SOAP web service
- Talk to a RESTful web service
- Talk to a pure POX web service
- Talk to a duplex service that can also start a conversation with Silverlight too
There are also many variations of the format of the message for the communications with Silverlight. For example, the data can be passed as pure XML, AtomPub, or even as JSON.
The first recommendation I hand out is to determine if the Silverlight application needs to talk to an existing service or one that you will create. If the service exists already, then the decision is heavily swayed to use that service in whatever state it is in. After all, why reinvent the wheel? If the existing service does not do all that you need it do do, then you can decide on creating a new service using your choice of the options.
When creating a service, REST and SOAP are 2 of the more popular choices. REST services offer a lot of value as they use HTTP as is, so any client that can talk HTTP can talk to your service. SOAP has additional features since it pads HTTP with its own wrappings. SOAP, for example, can add additional levels of encryption and message security on top of what is available through HTTP. There is no bad choice between REST and SOAP, but before making that choice I seriously recommend laying out all of the needs and wants for the service before plunging in. Sometimes this helps make the choice much easier.
When creating REST services you might only need it to return XML. However, it could be advantageous to also allow it to return the data as JSON, too. JSON is more compact and can be used more readily by some clients like AJAX. However XML is more easily read and widely used. The bottom line is that it is easy to make a service that has a switch so it can return the same data in either format ... so why not offer both.
Some large service providers like Amazon offer their API web services in both SOAP and RESTful formats. This is another option of your clients have varying needs. This takes a little more effort than simply creating a switch between JSON and XML formats, but if your client base is diverse and wants both formats, its certainly doable without killer effort.
There are many variations on how to use web services from Silverlight, how to call them, how to parse their data, and so on. Knowing how each service type works and their ups and downs can help get you through it pretty painlessly.




Facebook Application Development
The first recommendation I hand out is to determine if the Silverlight application needs to talk to an existing service or one that you will create. If the service exists already, then the decision is heavily swayed to use that service in whatever state it is in. After all, why reinvent the wheel? If the existing service does not do all that you need it do do, then you can decide on creating a new service using your choice of the options.
When creating a service, REST and SOAP are 2 of the more popular choices. REST services offer a lot of value as they use HTTP as is, so any client that can talk HTTP can talk to your service. SOAP has additional features since it pads HTTP with its own wrappings home business. SOAP, for example, can add additional levels of encryption and message security on top of what is available through dedicated server HTTP. There is no bad choice between REST and SOAP, but before making that choice I seriously recommend laying out all of the needs and wants for the service before plunging in. Sometimes this helps make the choice much easier.
We are facing a "strange" -at least for us- problem regarding network socket communication and Silverlight or WPF. We have developed a client in Silverlight that consumes a proprietary network feed with stock exchange data. The communication takes place over TCPIP using sockets technology. Due to the asynchronous nature of the communication we have a loop of continuous receiveasyncs. The complete event of receiveasync calls a new receiveasync etc etc.
The bytes received are stacked in a queue which is used by another thread for reading and deserialiazation of information. The same code is used in a classic windows service, in a silverlight client and in a wpf client. The first (windows service implementation) causes a CPU load of maximum 14% and the second (silverlight) and third (WPF) pump up the cpu load to 50-60% at least.
We've done some profiling to the wpf implementation to find out nothing of importance. Unfortunately, there is no profiling for silverlight and xperf does not give understandable results. Is there a pattern or some other info that might help us. I must say that we cannot change the stream of data we receive.
Regards,
Joseph @ Webdesigner
John, Excellent as always! I was wondering about this silly error I kept getting I thought I would have to buy steroids for SL to get it working. But thanks to you I've finally got it worked out. Thanks again.