Suddenelfilio’s Weblog

Icon

Passionate about .net

IIS 7: HTTP POST, DefaultDocumentModule and a forgotten ‘/’

Yesterday I experienced some issues when I was trying to access a generic http handler (*.ashx) file using only the path without the filename e.g.: http://localhost/somefolder

The default document was set to uploadhandler.ashx. So i expected that if I connected to http://localhost/somefolder it would sent me to http://localhost/somefolder/uploadhandler.ashx but it didn’t. Appareantly it has got something to do with not adding a ‘/’ at the end.  For the exact problem and also the reason why it didn’t work as well as the solution have a look at post of mine put up at the iis.net fourms http://forums.iis.net/t/1155013.aspx

Filed under: .net 3.5, IIS

Compact framework WCF, Disco files, netcfsvcutil

When using the 3.5 version of the compact framework it is possible to connect with wcf services. This is because the CF 3.5 contains a limited subset of the wcf technology. There are several blog posts listing the wcf capabilities in CF e.g.: http://blogs.msdn.com/andrewarnottms/archive/2007/08/21/the-wcf-subset-supported-by-netcf.aspx

We were researching for a mobile client to connect to a wcf service running at one of our servers. The requirement is that transport is secured by using HTTPS protocol.

The first problem was creating a client side proxy. Since the SvcUtil doesn’t work for the CF we had to look for an alternative. After some googling we found the netCFSvcUtil which is basically the same as the svcutil, but it generates a proxy specifically for CF. You can find it as part of the Power Toys for .NET Compact Framework 3.5. For more on this you can read this excellent blog post by Andrew Arnott

When you get this generated client proxy there is another problem. It expects that you are using HTTP. Since we need HTTPS that’s a problem. Thanks to Damir Dobric we found how to make the proxy use https instead of http.

System.ServiceModel.Channels.CustomBinding binding = new
    System.ServiceModel.Channels.CustomBinding();
binding.Elements.Add(new System.ServiceModel.Channels.TextMessageEncodingBindingElement
   (System.ServiceModel.Channels.MessageVersion.Soap11, System.Text.Encoding.UTF8));
System.ServiceModel.Channels.HttpsTransportBindingElement https =
   new System.ServiceModel.Channels.HttpsTransportBindingElement(); 
https.RequireClientCertificate = false;
binding.Elements.Add(https);
 

This way your client proxy is now HTTPS enabled.

 

Another problem we had was that the disco file was downloaded from the “wrong” location. We have a wildcard certificate in place for our HTTPS like *.domain.com. We were accessing the service using https://laptop1.domain.com/wcf/service.svc. Although this url works fine when we browsed to it, there was an issue when we tried to generate a client proxy. It seemed that both svcutil as netcfsvcutil were trying to download the DISCO file from https://laptop1/wcf/service.svc?Disco. When we browsed to this link it worked just fine. The problem is in the url and the wildcard certificate. Since the disco url didn’t include the domain.com part in its url the utils were not able to establish a trust relationship over ssl with the web server. This is perfectly normal since it does not correspond with our wildcard certificate.

The solution is to update the https binding in IIS by giving it a host header. Now this is something you can’t do in the IIS control panel. There are 2 ways of doing this: Using scripting or using the metabase explorer that can be found in the IIS 6.0 resource toolkithttp://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/993a8a36-5761-448f-889e-9ae58d072c09.mspx?mfr=true

 

A last advice don’t fall into the same trap by thinking that a wshttpbinding is required to do HTTPS, it’s perfectly possible by using a basichttpbinding where the security mode is set to transport.

Filed under: .net 3.5, .net Compact Framework, IIS, WCF

Visual studio .net 2010 & .net Framework 4.0 CTP

f2b64570-4956-4687-b2d7-58842cabbbe8 Today I found that the first CTP for visual studio .net 2010 and the .net framework 4.0 is available for download. If you want a quick overview of some of the new features go to this website: http://msdn.microsoft.com/en-us/vs2008/products/cc948977.aspx 

If you want to download the CTP you should go to the Microsoft Connect page

Filed under: .net, .net 2.0, .net 3.0, .net 3.5, .net 4.0, Visual Studio .Net 2010

MSMQ Message priority

In my recent development I’ve been using msmq to store messages that can’t reach a wcf service when it’s not available. I was setting the Message (System.Messaging) property Priority so that the queue would prioritize the incoming messages.

However when I looked at the queue all the messages their priorities where 0 or “Lowest”. It seems to be because my queue is transactional (which is a requirement for the msmqintegrationbinding). It was a bit of a disappointment that I couldn’t control the priority using the native msmq features, but hey that’s the price I had to pay for some other great functionality.

Filed under: .net 3.5, MSMQ, Visual Studio .Net 2008, WCF

WCF: msmqIntegrationBinding

Today I discovered the msmqintegrationbinding in the windows communication framework.

This binding is especially to allow wcf services to process message that are put in a message queue by some legacy program. The advantage of this is that you can do this without the need to change the legacy client.

If you want more information on how to use this binding have a look at this post at Simon Evan’s blog

There was something I liked in particular and it was exactly what I was looking for; I’m working on a custom logging framework adapted to our needs. To keep it simple let’s say that a Log class sends messages using the fast netnamedpipebinding in wcf to a service. This works fine, but what when the service is unavailable? Well I’ve designed the Log class to automatically failover sending the message it would normally send to the service to a queue. This way I don’t lose any of the log messages. The advantage I mentioned above is that when I reset the service (launch it again) it automatically starts processing the messages (logs) in the queue as well as accepting new log messages using the named pipes. So this way I achieve our main priority: deliver the log messages as fast as possible, but without losing them when the service is down.

Filed under: .net 3.5, Visual Studio .Net 2008, WCF

var crash = from feature in visual studio where feature.name.Contains(Silverlight 2.0 tools) select feature

i’ve been struggling to get the RC1 of the silverlight tools for visual studio .net 2008 going. So far I’ve tried the following:

- turning off UAC
- Repairing Visual studio setup
- SubinAcl from the following blog: http://petesbloggerama.blogspot.com/2008/01/fix-requested-registry-access-is-not.html
- Running vs.net as administrator

I always get the following error message:



  Personally I really am starting to hate the whole silverlight technology. The first version was crap because you had to be some guru to be able to program something fancy looking and now the second version is out and the tools are crap. So what’s next crappy visual studio .net 2010 all together? I really would like the guys at MS to take it a bit slower so they can increase the quality of their products.

 

Filed under: .net, .net 3.5, Silverlight, Visual Studio .Net 2008 , ,

Babysteps: LINQ To SQL

Okay I had some free time to spend on LINQ  To SQL and because I’m working on a new personal project for the future (God only knows if I’ll ever finish it ;-) ). I need in my database a table “Countries”. Because I don’t want to create a script to load this table  and I certainly don’t want to fill it manually I started looking for a web service that could provide me the data I need. I want to keep the country’s Name and its ISO code.
For this I found a web service on http://www.oorsprong.org [WSDL] which does exactly what I need.

The web service has got a web method – ListOfCountryNamesByCode – that returns all the countries with their ISO codes. Just perfect! :-D

Knowing where to get the data, we need to create the table that holds the data I’m getting from the web service. For this I only need a very basic table:

CREATE TABLE

[dbo].[Countries]
(
[ID] [int]
NOT NULL IDENTITY(1, 1),
[ISO] [nvarchar] (3)
NULL,
[Name] [nvarchar] (50)
NULL,
[InsertDate] [datetime]
NULL
) ON [PRIMARY]

Okay I admit maybe it’s not the best table structure ever, but it will do the trick.

So now the table is ready to store the data gotten from the web service all we need is to get the data.

First thing you need is to add a LINQ To SQL Mapping file (dbml file). Doing this is very simple. Just click somewhere in the solution explorer’s related project and select “Add new item”.

add new item - LINQ to SQL

 From the list you can select LINQ To SQL Classes. When the dbml file is created you just drag-n-drop the tables from the server explorer onto the designer’s surface.

dbml designer

That’s all you need to do for the object relational mapping for the Countries table. Also notice that when you drop the Countries table onto the surface of the designer it is smart enough to rename the autogenerated object to Country because it will represent the Country entity that is stored in the Countries table.

Next you need to fetch the countries using the web service. So just add a web service reference to your project, create an instance and call the necessary method, in this case it’s the ListOfCountryNamesByCode which will return an array of tCountryCodeAndName instances.

org.oorsprong.webservices.CountryInfoService serv =    new org.oorsprong.webservices.CountryInfoService();
org.oorsprong.webservices.tCountryCodeAndName[] countries =    serv.ListOfCountryNamesByCode();

To work with the generated Country entity you will first need to create a database context. The designer already generated all the necessary code for you. All you need to do is create an instance like this:

CountryTableDataContext db = new CountryTableDataContext();

Be honest it couldn’t be much easier ;-)

The instace db contains a property called Countries which is a Linq table for Country entities. Because we have a type difference from what is returned by the web service and what needs to get stored in the database we will convert the array of tCountryCodeAndName instances to an IEnumerable of Country entities. For this we can use the LINQ to Objects technology together with anonymous typing and object initialization expressions.

 var ctr = from c in countries
           select new Country() { ISO = c.sISOCode,            Name = c.sName, InsertDate = DateTime.Now };

As you can see we don’t define the type of ctr it will be implicitly defined as whatever is returned from the LINQ query. The part after the equals sign is the same as writing a foreach statement.
The second part of the code is where we create a new Country instance and assign it’s values using object initialization expressions. For example the Country entity has got an ISO property so you can say ” new Country() { ISO = c.sISOCode} ” to assign it the value of the property sISOCode on the tCountryNameAndCode instance c.

In C# 2.0 the previous code would look like this:

 List<Country> countryList = new List<Country>();
  foreach (tCountryCodeAndName c in countries)
  {
      Country ctr = new Country();
      ctr.ISO = c.sISOCode;
      ctr.Name = c.sName;
      ctr.InsertDate = DateTime.Now();

      countryList.Add(ctr);
  }

Of course there are some other techniques in the new way of coding that I didn’t explain like local type inference, lambda expression (behind the scenes)…

Now that we have got an IEnumerable of Country entities “ctr” we can add them to the database context very easily:

db.Countries.AddAll(ctr);

That’s it, just do this last line of code below and all the countries with their respective ISO code will be stored nicely in the database. Isn’t that cool ?!?

db.SubmitChanges();

If you have any questions on this post you can use the comment option to contact me about this.

Filed under: .net 3.5, LINQ, Visual Studio .Net "Orcas"

How to ignore a blogging career ?

That’s simple buy a house that needs to be finished in the meantime switch jobs and on top of that move out of your current appartement. :-)

I’ve not been writing as much as would like, but I can’t seem to find the time. Lately I’ve been watching more closely to LINQ, Nhibernate, EDM, Windows Server 2008 and Visual Studio .net Codename ”Orcas”… I know that’s a lot but I can’t keep up and I would like to explore as much as humanly possible under current conditions.

Anyways my findings in short are:

LINQ: nice
NHibernate: same as LINQ = nice + advantage current support .net 2.0 and older versions.
EDM: yeah well… nice as well :-)
Windows Server 2008: mmm still beta, should say enough.
VS.Net Orcas: surprisingly “stable”.

Filed under: .net, .net 2.0, .net 3.0, .net 3.5, Visual Studio .Net "Orcas", Windows

Get a history of the evolution to LINQ

 Anson Horton wrote a very nice article for the MSDN magazine June 2007 edition. It gives you an overview of how LINQ (Language Integrated Query) has evolved from the idea of the concept to an actual technology. A nice extra on this article is that he shows a lot which new language features in C# 3.0 made it actually possible to come to version on LINQ we have now. It’s thanks to Lambda Expressions, Extension Methods, Anonymous Type, Implicitly Type Local Variables, Object Intitializers and Query expressions that LINQ can offer you a very nice language enhancement to query for example objects, dataset, xml, …

Check it out at:
http://msdn.microsoft.com/msdnmag/issues/07/06/csharp30/default.aspx

Filed under: .net, .net 3.0, .net 3.5, LINQ, Visual Studio .Net "Orcas", Visual Studio .Net 2005

Installing Microsoft Codename "Astoria"

Since I’m going to take a further look at the Astoria project I’ve installed the necessary pieces to get started. Here I will give a brief overview on what to install.

The pre-requisites are:

- Visual Studio .Net Codename “Orcas” beta 1 Standard, Professional or Team Suite edition.

note: The Visual Web Developer Express Codename “Orcas” edition will work as well but the experience is not optimal.

- .Net Framework 3.5 (Pre-Release version)

- Sql Server 2005 database

- Microsoft Codename “Astoria” May 2007 CTP

- Virtual Pc or Virtual Server 2005 R2 (if you are going to set up a virtual machine )

1. Visual Studio .Net Codename “Orcas” Bèta 1

For this it’s up to you to decide on which way to go. You can either download the bèta software and install it directly on your machine or install it as a virtual machine.

Since most of the software isn’t final yet I prefer to install it as a virtual machine. So I downloaded the VSCTPBASE file which is a pre-installed virtual machine by Microsoft you can use for testing purposes. The advantage is that you can re-use this image becuase it’s set up in such a way that it contains the basic needs for a virtual machine and you can install it together with other images that contain the specific technologies that you want. In this Case I downloaded the Visual Studio .Net Codename “Orcas” Bèta 1 Team Suite VPC. This is download is seperated in 9 files you can merge after download.

Tip: Use a download manager to download all these files because I’ve lost connection a lot during the downloads.

Okay when you’ve downloaded the files you can get working:

- Extract the base image (VSCTPBASE.exe) to a folder of your choice. I took D:\VM’s\Base.
- Extract the 9 files containing the bèta vs.net. For this I took D:\VM’s\vsnet orcas beta 1
- Create a new folder Astoria Environment. I picked D:\VM’s\Astoria Environment
- Copy the files from step 1 and 2 into the newly created folder. This way you won’t mess up the images in step 1 and 2 and it enables you to use them again if you want to test something else in another vm.

Issues with Differencing Disks (I’m using Virtual Server 2005 R2)
The Orcas image is a differencing disk which means that it needs a base disk to operate properly. The problem lies in the fact that the differencing disk has got it’s base disk hardcoded in the configuration and thus probably cannot find the base image because the paths you are using will differ from the ones the creator of the images was using. You should change that path using the configuration of the differencing disk

Differencing disk properties.

When starting the virtual machine for the first time you will probably run in the same problem as I did. What the hell is the user’s password ??? Well this is mentioned on the download pages of the images.

<<TODO insert image of MSDN download page showing login passwords>>

Finally it might be a good idea of installing the Virtual Machine addon for an optimal experience. To do this follow these steps:

- Log into the Guest Os.
- Go to the administrator site.
- Go to the configuration page of the virtual machine.

- Click on the Virtual Machine Additions.
- In the new screen you check the “Install Virtual Machine Additions” and press OK. (remember that the vm must be running.)

Okay now you are logged in and it you can proceed to part 2 of the installation. The .net framework 3.5 installation.

2. .Net Framework 3.5 Pre-Release installation

If you are using the virtual machines like I do you can skip this step because the .Net Framework 3.5 Pre-Release is already installed in the image.

If you are installing it directly onto your machine it shouldn’t be more than just executing the installer.

3. Microsoft Codename Astoria

Finally the “fun stuff” :-) installing astoria. This shouldn’t be too difficult because it’s just a MSI.

1. Execute the installer file and check the License Agreement checkbox of course.

2. Press the install button and the installation will begin and after installation press the Finish button.

Well euhm to be honest, that’s it… really the effort worthy to write an article about it eh?

Okay maybe 1 last thing, check if it’s installed correctly:

If you need to install the northwind database you can download it from MSDN

Filed under: .net 3.5, Astoria, Visual Studio .Net "Orcas"