Finally .NET Framework 3.0 RTM'd, so I don't have to run in my VMWare anymore. A good time to see if everything works and create the host for the service contract we've created last time. We'll do this using a C# console application, as those just rock in simplicity.
We need a ServiceHost object to host our service. It implements IDisposable, so we'll use the using statement to create one.
using (ServiceHost host = new ServiceHost(xxx))
You'll hopefully immediately notice the three red x characters. That's where we have to insert a parameter, our servicetype. For us this is our Hello contract. We also need to open the host we created, before it's actually brought alive by WCF.
Type type = typeof(Hello);
using (ServiceHost host = new ServiceHost(type))
Console.WriteLine("The service is available. Press any key to continue...");
In the above final sample I first declare a type variable, assign our Hello service contract type to it and pass it into the constructor of our ServiceHost instance. I then open the service, show this in the console window and ask the user to press a key to close the service. Else the service would close immediately.
WCF however needs some information from configuration. It can all be done through code, but of course we like our app.config much better. We need to specify our WCF ABC. We've already created our contract, but we have to let WCF know what contract belongs to what binding on which address. First, compile your application. Then, in your project you can add the app.config, right-click it and select 'Edit WCF Configuration...' and you'll see the Service Configuration Editor. Select 'Create a New Service..." and you'll be presented with a nice wizard.
The first step we need to tell it what service we'll want to use, where the implementation of the service is. Select to browse and lookup your console application it's executable and select it. You'll see your Hello class, which you'll have to select. The next page of the wizard will now just know that IHello is the contract we've used. Now we'll have to select the first part of our binding, the protocol we'll start using. Leave it at default. In the next step we'll also choose the default setting. The difference between these two can roughly be described as standard ASP.NET ASMX webservices, where the second means WSE 3.0 extension.
Last thing of the WCF ABC is to select the address. You might want to choose http://localhost:8080/HelloService/. We'll then get an overview of our selections and you can press the finish button. Be sure to check out what the wizard has changed inside the Service Configuration Editor. You'll only have to research the "Services" folder as we did not yet change the others. After saving and looking at our app.config, we should find the following.
<?xml version="1.0" encoding="utf-8" ?>
Notice that we have one service. In the above configuration you can see my namespace Classa.Wcf.Samples. which I added extra. In the attachment I've included you can see where exactly this comes from. Also the bindingConfiguration attribute isn't really necessary right now. What is important that we see our WCF ABC return again. Address, binding and contract!
You can run this and your service will run and be live, but noone can tell how to communicate with it. For this, we need metadata! But that's for the next post.
[Go to the WCF series article index]
Just upgraded Community Server 2.1 to Service Pack 1, downtime was only a few minutes. Thanks Telligent.
Be sure to check out Blogmailr.com if you want to blog using e-mail, for free. I still prefer Windows Live Writer though for the features, the SDK and the great preview you get, when your skin is downloaded correctly J
Uploading images using blogmailr doesn't seem to work correctly, I'll have to look into our metaweblog code. Using Live Writer it does work though.
For the first time in my life I'm playing around with the new SQL Server 2005 .NET CLR integration. A mouth full, as everything with Microsoft.
The most easy way is to start a new Database\SQL Server Project. You then right-click the project and select to add a "Stored Procedure...". In your newly created class you can produce something like this:
public static void MyFirstStoredProcedure()
After that, look in the "Test Scripts" directory and find the Test.sql script. In it you'll want exactly one line.
If you haven't done so already, enable CLR integration in SQL Server 2005.
sp_configure 'clr enabled', 1
Next step is just hit F5, but only when you have SQL Server 2005 on the machine you're working on. On my machine, it sometimes completely locks up, but comes back after a minute or so. Great huh?
In your output window you should see the "dude!" message. Let's see how we can enable this on a server that's not locally run. With Management Studio you connect to the remote server. If you haven't changed the name of your project, it'll be 'SqlServerProject1'. Let's register it.
IF EXISTS (SELECT * FROM sys.assemblies WHERE [name] = 'SqlServerProject1')
DROP ASSEMBLY [SqlServerProject1]
CREATE ASSEMBLY SqlServerProject1
WITH PERMISSION_SET = SAFE;
Now in the above code, you can see the exact command to remove the assembly if it already existed (which isn't very likely ;) and to register it. However, when creating this post, at some point this didn't work anymore. I'll come back to this, but in the meanwhile while you get an error, it's also possible to register your assembly in Management Studio. When you go to your database, open the "Programmability" folder, and then "Assemblies". Right-click it and choose to add your assembly.
Now let's register our Stored Procedure.
CREATE PROCEDURE StoredProcedure1
AS EXTERNAL NAME SqlServerProject1.[SqlServerProject1].MyFirstStoredProcedure;
When you go look for your StoredProc, you can see a little lock symbol in the icon. That's because we registered the assembly with permission to safe, so the asssembly can't access the drive, registry, etc.
Now you have a C# Stored Procedure in SQL Server 2005. However, that's not why I was initially writing this post. I just kept getting errors registering my assembly and could not figure out why. The error was :
Could not impersonate the client during assembly file operation
After searching Google, it should have something to do with not being able to access the file or something. But it happened to me all the time when I was trying to register my assembly on the remote SQL Server. Even when I used an incorrect path to my assembly. I started to think they used the following code to register assemblies.
public void RegisterAssembly(string fullPath)
// code to register assembly
// Console.WriteLine("Dude, something went wrong!");
Console.WriteLine("Could not impersonate the client during assembly file operation");
For some reason it works now and the error doesn't return, hopefully.
If you want more info on SQL CLR integration, download some samples here.
Some time ago I had a discussion with my colleague Alex Thissen about the differences between Visual Studio 2005 (unit) testing, and NUnit and TestDriven.NET. I'm very pro NUnit, but Alex says he can do everything I do with VS2005. I disagreed and we talked about bitchslapping, or perhaps some bitslapping on our weblogs. Nothing came from it though.
I just noticed TestDriven.NET 2.0 has been released and it has some awesome features! For n00bs, TestDriven.NET offers Visual Studio integration for NUnit. When you take a look at Jamie Cansdale his RTM post on his weblog, you'll notice some awesome features like:
- Reflector integration
Reflector is the must-have tool for every developer, and the new integration from TestDriven.NET is just plain AWESOME!
- Code coverage with NCover or Team Coverage
- Our new best friend, "Repeat Test Run" :)
- Test with .NET 1.1 from within Visual Studio 2005
- Pluggable unit testing frameworks.
- TypeMock.NET integration
So what are you waiting for? Download, download, download, download... NOW!
Jan wrote that he sees possibilities in Windows Presentation Foundation, for one that he doesn't need to bother with the design anymore. For developers this is indeed very good. I can see applications build in the future where you're obliged to some interface guidelines, but you just throw some controls on the screen without detailed concerns of the final interface. When you're done adding all controls, a graphical designer can transform it into a great looking screen.
But also for businesses there are great possibilities. In a podcast I listened to, some Microsoft fellow talked about an application for a car rental company. When you tried to rent a car, very subtle it offered some extra options you could add to your car. WPF helped in the subtle presentation that could trigger people to notice it, without being too obstructive. And it did that far better than current presentation techniques (Windows Forms or HTML) could do so. All for better revenue for the car rental company.
I do believe this really is what Windows Presentation Foundation has to offer. I have no clue in how, but I'm sure that great graphical designers can come up with awesome stuff.
Erwyn is regularly blogging about his Amsterdam apartment and skyline. Although I don't actually live in Rotterdam, I'm currently working at one of the most beautifully locations available, the Van Nelle fabriek. It's a 'rijksmonument', a very old building with governmental funding to keep it in its original state. A great location to work at.
Because it's fall a lot of rain is falling, but from times to times the sun also shows itself. This resulted in a beautifully view from my workspace onto the skyline of Rotterdam!