views:

29

answers:

2

Hi, I need a very weird thing I admit. I hope you'll be able to help me.

My current situation (all in one solution VS2010):

  • I have the Silverlight assembly with user-control (basically a drawing of kind)
  • I have a WCF service to provide the images (hosted in the website project)

I somehow need to:

  • when someone requests the RESTful service (above) for the image of a certain size
  • create, set-up and render that control to an image (I did it using the WriteableBitmap)
  • return the image to the service somehow <-- THIS IS MY PROBLEM
  • provide that image as a response (I know how to do that)

I've tried to reference the Silverlight assembly (from non-Silverlight assembly) with helper class returning the image. But that's just ugly.

  • Is there a way to host the WCF service that is inside Silverlight ?
  • If no, is there any other way to get the image from the Silverlight -> non-Silverlight service class

Thanks, Kate

Note: The Silverlight control is a massive one, and used in three other projects (editor, viewer, windows phone 7 application) so I can't really move it. Also Silverlight's WPF-like drawing is far superior to non-Silverlight.

A: 

Perhaps this will help:

http://blog.galasoft.ch/archive/2008/10/10/converting-and-customizing-xaml-to-png-with-server-side-wpf.aspx

JeffN825
This is good, but I guess it's unusable in this case, as it is not just parametrized xaml file (which can be stored on the service side), but whole lot of drawing via Silverlight code. The code has to be invoked somehow.
SmartK8
+1  A: 

There are lots of ways to do this, and I'm not entirely clear on what you're trying to accomplish, but something like this should work:

(1) The WriteableBitmap.Pixels property should contain an RGBA version of the image in question.

(2) Use FJCore to convert the RGBA bytes to JPEG format.

(3) Submit the JPEG file (contained in a byte[] array) via a call to the web service.

(4) On the web service, save the file in some appropriate location, where the other non-Silverlight applications can access it.

Would that do something like what you need?

Ken Smith
It is just the other way round. Service has to made a parametric request to Silverlight somehow. SL will render the image based on the parameters sent, and returns it to a service. But how to make request WCF service (non-Silverlight assembly) -> Silverlight assembly
SmartK8
Is the Silverlight assembly running on a client somewhere? Or are you trying to host the Silverlight assembly within a WCF service? It sounds like the latter. If so, there are two ways of doing it: if the assembly is simple enough, it may be possible to just reference the assembly as described here: http://blogs.msdn.com/b/clrteam/archive/2009/12/01/sharing-silverlight-assemblies-with-net-apps.aspx. Alternatively, if you've got access to the SL source, you can reference the relevant SL source files in a non-SL project as described here: http://msdn.microsoft.com/en-us/library/ff648215.aspx
Ken Smith
The SL code is heavily dependent. It's basically the UserControl (which draws itself specially) containing many other UserControls (also drawn). Moving it outside to a non-SL assembly is what I'm trying to prevent here. Because it would be basically a port of graphics routines, and the quality would be hard to achieve. Also the important thing is it has to be exactly the same in look. I'd like (ideally) to host that WCF service inside the Silverlight directly. Is that possible ? And then reference it in website ?
SmartK8
To explain further what I'm trying to do. This user-control's look is viewed by a viewer application, edited in editor. All shared in a common SL library. Now I need an independent service to return image of this control also. So the client in his browser has requested image of certain parameters. I'm now in my WCF RESTful service which received this request. I don't know how to connect to that SL library to generate that image. If the WCF service itself was in the SL than this ugly, ugly call wouldn't be needed, and the image could be generated directly via referenced library.
SmartK8
Ok, I've found two ways to do it, but both are ugly and slow. So I've resigned and I've started to port the graphics routines (sigh). 21k errors, see you next year.
SmartK8
I'm still not perfectly clear on what you're needing to do, but have you looked into duplex WCF? That may be what you're looking for by asking if WCF can be hosted inside Silverlight. If a Silverlight client is connected to a WCF service, the WCF service can make calls against the Silverlight client using either a Net.TCP or an HTTP Polling Duplex binding. See http://tomasz.janczuk.org/2009/11/pubsub-sample-with-wcf-nettcp-protocol.html or http://tomasz.janczuk.org/2009/07/pubsub-sample-using-http-polling-duplex.html.
Ken Smith
Thanks, that's the answer I was looking for. Unfortunately I've already ported the graphics routines to .NET (for better I hope). Still thanks a lot.
SmartK8