Sorrow with Data Transfer Objects in Silverlight / WCF - silverlight

I have a Silverlight app hosted in an Azure web role ASP project. The ASP project exposes a WCF service.
I would like to have one set of class definitions for the data types. Someone recommended making a third project (class library) and adding a reference to it from the SL and ASP. I started doing this, but the Silverlight project complained that you can only add references to Silverlight projects.
I then made a Silverlight class library and moved the data classes to it. However, I to add some .dll references, like to the Windows Azure storage client. Then the Silverlight class library tells me I can only add references to Silverlight 4-friendly .dlls, of which Windows Azure isn't one. Fantastic.
Is there something I can do to get around this, or am I stuck with a less elegant, redundant solution?

Multi-targeting is your best bet. There is an article explaining this in Visual Studio from Microsoft at:
http://msdn.microsoft.com/en-us/library/ff921092(PandP.20).aspx
Basically, you create both your Silverlight and standard .NET class libraries, each with a different name, and then include the same files into each. Usually the files are actually only in one of the class libraries and then soft linked in the second one.
The key is to ensure that the code in your files is compatible with both runtimes. If there needs to be separate implementation for some of your methods depending on the runtime then you need to separate these with pragmas (i.e. #ifdef SILVERLIGHT...).
If you're only doing data structures, however, there should be no issues as long as Silverlight supports the objects you are using.

See if using linked files as per this answer does the trick for you.

Related

Sharing external SDK binaries to WPF and Silverlight

I've been trying to sort this out for some time now..
I have a few .NET libraries that work as an SDK to an external application. I need to use that SDK both from a WPF Class Library and a Silverlight Class Library. I've been reading a lot of solutions including:
Portable Class Libraries - When I try to add the SDK libraries to the project, it complains that those libraries reference .NET 2.0 libraries and it is incompatible.
WCF RIA - I may be doing this wrong, but everywhere I turn, one step of the process is to create an Entity with the EF. Now, I don't want to access a DB, just those libraries.
But so far, no luck. Any ideas you would like to share?
As far as I know, it may not work if the old .NET 2.0 binaries have references to COM or system libraries. That could relate to your DB implementation. I have had this problem in a project in a previous job. We solved this by creating a WCF service as a in-between solution. That was WCF and not WCF RIA.
If the .NET 2.0 code is really old, you should check if it must be compiled as x86 and hosted as a 32-bits application on AppPool of the site that hosts the WCF service in the IIS.
But this is tricky business, and it all depends on the complexity of the old .NET 2.0 library file and its references.

Coded UI Testing of Silverlight in Sharepoint 2010

I am creating a Coded UI test for our system which runs on Sharepoint 2010. Part of the test sequence is creating a site; Sharepoint's UI for creating sites runs on Silverlight. Therefore, I need to create a Coded UI test for a Silverlight component which is part of out-of-the-box Sharepoint rather then part of our application. When I try to record a test, I get the following message:
No Silverlight controls where detected. Verify that the application under test is built using Silverlight assemblies with a version of 4.0 or greater and that a reference to the Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll assembly has been added to the project. For more information, see http://go.microsoft.com/fwlink/?LinkId=204562
I have two questions:
1) How can I find out the Silverlight version which Sharepoint components are built against? If they are built against Silverlight version 3.5 or earlier - I suppose the problem is unresolvable?
2) Assuming the previous question is answered - how can I make Sharepoint's Silverlight components reference the SilverlightUIAutomationHelper.dll library? That seems problematic at best to me...
Silverlight version installed on the test machine is 4; Visual Studio Feature Pack 2 is installed.
Thanks.
You can't make SharePoint's Silverlight components reference the automation helper library unless you have the source code and can recompile them. So the answer to your first question doesn't really matter.
You could modify Sharepoint XAPs to simply add Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll in there. You don't really need the code itself to reference it, it just has to part of the package. The XAP file is just a zip file so you should be able to modify this.
You will have to find where Sharepoint is getting the XAPs from and change the source (obviously you don't want to do this in prod boxes and there's even a license restriction for the Automation dll that prevents you from do it). You could also write a Fiddler AutoResponder to modify the XAP file and add the dll before it gets to the browser. For an example of this have a look at this AutoResponder:
https://bitbucket.org/mamadero/hackingsilverlightdemo/src/2fecb7b59dec/FiddlerAutoResponder

Self hosting RIA Services in WPF executable & Referencing SL RIA Class Library

I want to use a RIA Services in WPF (Please hear me out before voting to close this :)).
I learned about being able to use RIA Services for other clients. Also looked at the sample progam (the famous HRApp) for consuming DomainServices from WPF using RIA Services Toolkit.
Unfortunately, none of it gave what I needed (explained below).
I was struck by a thought when I was looking through the walkthrough for making the RIA service client context & the domain services into reusable class libraries.
My idea is this:
Have a SL class library maintain a RIA Link to a Domain Service class library. Reference SL Class library (now extended with my own entity extensions) in WPF. Also Reference the DomainService as a class library and then Self-host using this trick inside my WPF app.
Unfortunately, the code is not compiling if I add System.Windows.dll to my WPF project. (Resharper additionaly complains I need to add System.dll too... but that appears at the moment to be a false alarm).
My needs are this:
Self-host a WCF service that allows me to CRUD (without me writing any code).
The WPF exe that self-hosts can accept connections from instances of the same executable running within LAN with just firewall configuration (where needed). In other words, I want the application to work as a server for its own copies running on other machines OR a standalone client
Just by changing a Option inside the program (or app.config) I can connect to a difference instance (for data consolidation and other processing on the server)
My application is very simple (3 tables at the most). Very simple querying needs
Be able to use ADO.Net Entity Model (and Entity)
Allows me to extend my entity classes akin to what RIA offers
Any pointers as to what my options are would be greatly appreciated.
Thanks in advance.
WCF Data Services was (formerly ADO.Net Data Services & Astoria) what I was looking for. It's remarkably similar to RIA Services.
It satisfies 4, 5, & most importantly #6 of my needs. I was able to self host simply by referencing the Service assembly solving #1, #2. I wasn't really looking for answer for #1 - #3 anyway.

Are there Silverlight assemblies for Windows Azure SDK 1.2

Just wondering if there are Silverlight (4) versions of the following assemblies
Microsoft.WindowsAzure.StorageClient
Microsoft.WindowsAzure.ServiceRuntime
Microsoft.WindowsAzure.Diagnostics
No, these libraries are not compatible with silverlight. First, the ServiceRuntime and Diagnostics libraries are completely useless to silverlight. Those are only relevant to hosted roles. As far as the StorageClient, while there is no dll for that there are a number of different approaches. I would recommend using the newly release RIA services for table storage as part of your solution. You can find that here: http://www.silverlight.net/getstarted/riaservices/
Also see this discussion for more details. Basically, you will want to use WCF services to expose you blob storage, etc. to your silverlight client. http://social.msdn.microsoft.com/Forums/en/windowsazuredevelopment/thread/b5e6775a-289f-438d-be79-8414f08c5c78

add reference to Silverlight project from other non silverlight project

I have Silverlight application using NHibernate as a ORM. I have projects for Data(mapp and entities), data access and Silverlight. I want to add to SL project reference to data access to execute methods, but SL can only get reference from other SL project.
How can I omit it? If I host data access project on WCF I could reference WCF to SL?
Please help ! :)
Yes, you can expose your data access assembly as a bunch of WCF services and then call them from the SL application.
There is also another way - make a Silverlight class library, and then add new linked files to it - those linked files being the class files from your data access assembly.
Here is a previous answer that explains the linking, although you should note that because your data access classes will now being using the Silverlight runtime you may not have access to all the System namespaces that you want (although you can pick and choose what files you want to add to the new project, and refactor the ones that don't work because of this).

Resources