Implementing the Windows Identity Foundation of Windows Server 2003 and experiencing errors such as the following?
System.NotSupportedException, mscorlib, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089
ID6035: Cannot create a HashAlgorithm with name 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'using the 'System.IdentityModel.Tokens.X509AsymmetricSecurityKey' crypto provider. SHA256 may require a minimum platform of Windows Server 2003 and .NET 3.5 SP1.
The same error can be experienced if you try to use FedUtil.exe on Windows 2003. Attempts to do so will result in the following error message;
Object Identifier (OID) is unknown
No doubt you have ensured that you are indeed on Windows Server 2003 (doh!) and indeed have .NET Framework v3.5 with Service Pack 1.
This error is due to, in some cases, the HashAlgorithm not being registered on Windows 2003.
Microsoft have published a HotFix that solves this issue. I have found that the hotfix requires a server restart upon installation.
Sometimes it is helpful to mock a xml webservice for the purpose of testing against it without invoking the actual service. There are several reasons why this can be a good idea, such as when the service is not hosted by you and therefore not under your control or in situations where calls to the service incur some kind of cost.
In my case, I wanted to mock out a service so that the scope of my unit testing was just my integration. I also wanted control over the service response to emulate a range of scenarios.
I would typically have developed a mock implementation using WCF however using an ASMX seemed the simplest method at the time, and I like the (Keep It Simple Stupid) KISS methodology.
So, here are the steps.
Step 1 – Create the ASMX file to host the service
In my case I already have a Test web application from which I host several test service stubs and other things, so it is simple for me to Right Click > New Item > Web Service.
Change the filename to something meaningful, such as <ServiceName>Mock.asmx
Step 2 – Generate a service stub from WSDL
Open a console window, I typically use the console that comes with Visual Studio (Available from start menu) and navigate to the folder containing the ASMX file you generated.
Type the following;
wsdl <URL of WSDL file> /language:CS /server
The URL is the full URL of the service you are wishing to stub out. In particular, I ensure the URL is that of the WSDL file.
/language can be your language of choice, in my case CS for C#.
/server specifies that you are wishing to generate code that would host such a service
A full list of options can by obtained by simply typing wsdl from the command line.
Step 3 – Modify your ASMX to ‘host’ the generated code.
By default the code behind for your ASMX will derive from
You want to change the code behind to derive instead from the code you generated in step 2. To find out which class to derive from, search your generated code for the class decorated with the System.Web.Services.WebServiceAttribute.
Once you have done this, compile your project. If things are as they should be the build should fail because you have not implemented the expected methods of the service.
Implement the services, throwing a
throw new NotImplementedException();
for now if you like – we just want it to compile.
Once you have done this, compile your project and open your ASMX in Internet Explorer (or your browser of choice)
If all is well, you should see a web page, with the name of the service at the top in a blue panel.
Step 4 – Customise your service logic (Optional)
As i mentioned, I wanted to be able to manage the responses I received from my service. This is done by modifying my implementation of the service that I have just created in the previous steps. Simples.