Struggling thru .NET
.NET is a huge thing and we have started to use it. We are going to blog about things we find out and things we find online related to everything .NET. This includes .NET, Linq, Silverlight, XAML, and anything else related to .NET.
Thursday, January 26, 2012
More postings!!!
I just published a project up on CodePlex.
http://kinectvoice.codeplex.com/
This is a small sample on how you can control a PowerPoint presentation using a plugin and the Kinect. Microsoft is releasing a Windows version of the Kinect next week and this will be a good start for voice controls.
Lots more happening in the WP7 world and gaming world here in Rochester, NY, but I will post about this later.
Read more...
Thursday, January 27, 2011
A Trip Thru Azure (part1)
I have the need for some storage for audio files for a website that I have hosted for years. After cleaning up a test file it ended up being about a 56M mp3 file. This would be a good test for Azure Storage and blobs.
Looking at the code for Azure, it seemed that I needed to use the API to code the saving of the files. I figured that someone wrote an app for it already and found one named Blobber. In the config file for the app, you had to put in the AccountName, SharedKey, and ContainerName for where you want things stored. So after getting the AccountName and the SharedKey that I setup in the Azure account site. I was not sure what the ContainerName was. The blob storage does not use folders, but uses the ContainerName as a virtual folder to help sort your data. So I created the ContainerName of audio. Running the app, it took a long time to upload the 56M file.
Then I started to test the downloading of the file. I created the url that it should have been http://accountname.blob.core.windows.net/audio/blobtest.mp3 put it in a browser and.... nothing. It did not work. I tried one thing after another and came up with nothing.
I then found a great little application called CloudBerry Explorer for Azure Blob Storage. This allows you to access your cloud storage just like you would in explorer. You can add/remove files and containers. With a right click, it allows you to get a url to the blob. It also had options to have a time limit for the url using parameters. I got a url with a timelimit until the end of the month. Put that into my browser and it worked great.
I was very happy to finally have some success, so I emailed the link to others and went to bed. The next morning I get a reply saying that the link does not work. I did some more research and found out that the link with time limits only lasted one hour. After a couple more emails saying that it did not work, I tried to figure out why. I ended up emailing a friend that works at Microsoft and does alot of talks on Azure, Jim O'Neil. He had the answer for me quickly. Containers get created as private to start. Jim suggested to change the container to public. Once I did this, the url worked great.
Ok, this first step into the world of Azure was a success with abit of help. I can store large files and serve them up with a url to let others get at them. The next step for me is to get Azure SQL setup to support a couple of phone apps that I am building.
Read more...
Thursday, August 19, 2010
RIA Services thru Web Services
Intro
I have been using Silverlight 4 and RIA Services on a large project lately and love how easy it is to expose a data layer with it. I was working on a different project with a co-worker using Silverlight 3 and my friend created proxies to get to the database and it was extremely messy code. I look back at it and just wondered what we were thinking about when we did it. Hind-sight is usually 20-20 and this was proving that saying since RIA Service is so much simpler to use.
I also create other things like iPhone/iPod/iPad apps using MonoTouch and am starting to look at the new MonoDroid for making android apps. One thing that would be very useful for a few of my projects will be a nice Web Service to save data into a SQL Server. I always could manually make a Web Service to get and store data off, but I wanted to see if there was any way to do it with RIA Services creating the data layer for me. It took some digging and searching but I found a way to do it and want to share this on the blog.
Machine Setup
To get this setup and running I have Win7 running with the following software and toolkits. I did not have the RIA Services Toolkit at first and that was a problem that I will talk about later, but you should be able to run the code samples here using the following.
Visual Studio 2010
Silverlight 4
RIA Services Toolkit
Silverlight Developer Tools
Demo Project
I wanted to come up with a nice simple example. I am sick of NorthWind, and I cannot use the database I am using for my Silverlight projects that I am currently working on. So I came up with the idea of doing a task list system. I wanted this to be simple, so I setup the database using the following schema and filled the database with some sample data.

User Data
1 | Steve |
2 | Joel |
3 | Paul |
4 | John |
Task Data
1 | 1 | Update Blog | 1 |
2 | 1 | Finish project | 4 |
3 | 3 | Buy coffee | 1 |
4 | 4 | Unpack from vacation | 2 |
5 | 4 | Report back to base | 1 |
Silverlight / RIA Projects
I started this project with the Silverlight project that had RIA Services enabled in it. I added a new database to the sample web project and put the schema and data above into it. Then I added the Entity Framework Model to the web project as well and added both tables to it. After this I added a Domain Service to the project to allow the Silverlight app to get to the data.
In the Silverlight project, I then added a combobox and a listbox to show the data. One of the things about using RIA Services is that calling the queries are done asynchronously. The Load method of the WebContext is used to call the query and provide a method to call with the results.
/// <summary>
/// Method to handle the loaded event to load up the users for the combobox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
theContext.Load(theContext.GetUsersQuery(), OnUsersLoaded, null);
}
/// <summary>
/// Method called after the users are loaded from the RIA Service query
/// </summary>
/// <param name="loadOpp"></param>
void OnUsersLoaded(LoadOperation<Web.Models.User> loadOpp)
{
comboBox1.Items.Clear();
foreach (var item in loadOpp.AllEntities)
{
ComboBoxItem cbi = new ComboBoxItem();
cbi.Content = (item as Web.Models.User).Name;
cbi.Tag = item;
comboBox1.Items.Add(cbi);
}
}
Then on the selection change of the combobox, the tasks for the selected user needed to be loaded. Now since the query runs over the connection on the web server, I wanted to limit the data that was coming back. But by default there was no method created to just get the tasks for a user, so I added the following method to the Domain Service.
/// <summary>
/// Method to get the tasks for a user
/// </summary>
/// <param name="userId">UserId for the user that we are getting the tasks for</param>
/// <returns></returns>
public IQueryable<Task> GetTasksByUser(int userId)
{
return this.ObjectContext.Tasks.Where(t => t.UserId == userId);
}
Now I was able to query the RIA Service for just the tasks for the selected user. This code was then added to the Silverlight project to display the tasks.
/// <summary>
/// Method for handling the selection change on the user combobox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
theContext.Load(theContext.GetTasksByUserQuery(((Web.Models.User)((ComboBoxItem)comboBox1.SelectedItem).Tag).UserId), OnTasksLoaded, null);
}
/// <summary>
/// Method to handle the return of the tasks from the RIA Service
/// </summary>
/// <param name="loadOpp"></param>
void OnTasksLoaded(LoadOperation<Web.Models.Task> loadOpp)
{
listBox1.Items.Clear();
foreach (var item in loadOpp.AllEntities)
{
listBox1.Items.Add((item as Web.Models.Task).Name);
}
}
Now I had a Silverlight app that got its data from the web server and the database attached to it. It is a small simple sample of a Silverlight/RIA Services project that can be expanded on for more complicated projects.
Adding SOAP Endpoint
To allow a standard Web Service to be used a SOAP endpoint needs to be added to the web.config. This was a simple thing to add to the web.config from samples that I found online. The highlighted section below was added to make sure that the wsdl is enabled for discovery.
<system.serviceModel>
<domainServices>
<endpoints>
<add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</endpoints>
</domainServices>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Now I also need to add a reference to the Microsoft.ServiceModel.DomainServices.Hosting assembly. But I did not see this at all in the list of assemblies. I did some more searching and found that I needed to have the RIA Services Toolkit installed to have this available. I found this, installed it, and was up and ready to go.
Adding the reference and the app.config changes was what I thought I needed to do, but I had a small problem when I tried to reference the service. I could not get the name right. It turns out that the service automatically gets put into a virtual folder named ~\Services. All of the websites that have information on this say that the service is named by the namespace-class. One of the things that nobody says is that you need to change all '.' in the namespace or class into a '–'. Without using this type of naming, you will not be able to discover the service. When I ran my sample and tried to add the web service, I had to use the following address.
http://localhost:49423/Services/RIAasWebService-Web-Services-RiaWSDomainService.svc?wsdl
Client WPF App
I decided to use WPF as the client app since I use that the most and I can reuse some of the code from the Silverlight to this project. I made the project the exact same as my Silverlight, with a single combobox and a listbox.
When I added the web service I used an Advanced setting to add the async methods from the service. This allows you to call just like in the RIA Services call and get a callback when it is complete. I wanted to test out using it the other way, so I did not use the these methods, but I checked them out to see if they were similar to the RIA Service versions and they are close. This simplified the functions to only two.
/// <summary>
/// Method for loading the users from the Web Service
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var users = ws.GetUsers();
foreach (var item in users.RootResults)
{
ComboBoxItem cbi = new ComboBoxItem();
cbi.Content = (item as User).Name;
cbi.Tag = item;
comboBox1.Items.Add(cbi);
}
}
/// <summary>
/// Method for handling the selection change for the users to load the tasks
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var tasks = ws.GetTasksByUser(((User)((ComboBoxItem)comboBox1.SelectedItem).Tag).UserId);
listBox1.Items.Clear();
foreach (var item in tasks.RootResults)
{
listBox1.Items.Add((item as Task).Name);
}
}
There is a bit of a delay in starting the app because it is calling the web service to get the users before it shows up, but this was expected with how I called the services.
Issues
There were a few issues as I was trying to get this up and running. The first, I already mentioned was the RIA Services Toolkit was needed to get things to work. Then there was the naming issue when I tried to connect to the service.
Using the ASP.NET Development Server, I could not connect to the service it was hosting from another machine. I would have to put the projects into IIS on my development machine and then expose it to the rest of my network. This would allow me to test it going to an iPhone app. I wish this was simpler, but the tasks to do this are not hard, but I did not get this tested.
Conclusion
Having a RIA Service exposed so that it can be consumed like a standard Web Service can be a helpful thing. It allows non-Silverlight apps to use the same data and especially since Silverlight cannot run on an iPhone or Android based phone. To make some phone apps that all use the same information this type of technique can be used. One thing to remember when you use this sample code, you may have to refresh the web service with the localhost port that visual Studio sets up for you. Or switch things to get it running in IIS. Good luck with it and I hope the code and article help.
Read more...
SQL Azure Pricing Changes
I know I am a bit late with this post, but wanted to spread the news of the changes to the pricing for SQL Azure. I have been looking at this myself lately because I am debating moving hosting companies and might need the extra SQL space.
SQL Azure had two options to start with. This was a 1G database for $9.99 or a 10G database for $99.99. This is an easy to figure out linear system. It looks like there are people that wanted something else in-between and even larger.
Web Editions | |
1G | 9.99 |
5G | 49.99 |
Enterprise Editions | |
10G | 99.99 |
20G | 199.98 |
30G | 299.97 |
40G | 399.96 |
50G | 499.95 |
They are setup for the smaller users and then targeting large databases. But you are limited to 50G right now. So if you need a larger one, you will have to split it up to use Azure. I am looking at using this for a project or two that I am working on. It is not a bad price and using SQL Azure should be as simple as normal SQL Server. If/when I get a database setup with this, I will be sure to post about it.
Read more...
Tuesday, June 22, 2010
RIA Services Updating Queries
At first, I thought it was an IIS caching issue. I have seen IIS do this with other projects. We tried a few things and it did not work at all. So I did a little bit a research on the RIA call that I was using for the callback. I was using this call...
theContext.Load(theContext.GetInfoByPageQuery(page), OnAllInfoLoaded, null);
Looking at the Load help, I tried out a different version that adds a LoadBehavior to the parameters.
theContext.Load(theContext.GetInfoByPageQuery(page), LoadBehavior.RefreshCurrent, OnAllInfoLoaded, null);
When I put this on the server it updated everything perfectly. This is something that alot of the online samples do not have in them so I thought I would share it.
I will be posting more about my adventures in Silverlight 4 and RIA services soon.
Read more...
Thursday, March 25, 2010
BizSpark
BizSpark
http://www.microsoft.com/BizSpark/
Read more...
Friday, September 18, 2009
.NET on the iPhone
You are able to use C# on the iPhone and iPod Touch. C# is the only .NET language supported right now. It uses MonoDevelop as the IDE for developing but uses the normal Interface Builder that you use from XCode, which is the default development platform for iPhone development. So if you are going ot use MonoTouch, you still need to have a Mac. I purchased a MacMini for my iPhone development. I know, I know, it is not a Microsoft product and I have drank the MS koolaid. I had put off doing this for a while but in reality it is the best way to get an iPhone app developed. It is not the only way but the simplest. Plus normally iPhone apps are written in Object-C. I can safely say that I really dislike Objective-C. C# is so much easier to use for me because I use it all day long and have for years.
Now this is the first version of the system. And on the iPhone you cannot have dynamically linked components. Everything is linked into the executable, so MonoTouch had to do that as well. They also provided a way to call a C library so that you can have things built in Objective-C and used in a C# based product.
Currently they have two versions available, Individual and the Enterprise. This is if you want to do enterprise releases or not. They are talking about an evaluation version soon, but did not get it out when they released. overall it is not a cheap tool for a single person, but if you look at it from the cost of your time, you will easily make it up in the first app that you develop.
Yes, I know that this is a post on iPhone development and I am actually spending alot of time on this myself right now, but it is also using .NET. It shows that .NET is a popular system that people want to use on many different platforms. And this is the first time it is available for the iPhone.
Read more...