However it’s possible to test your WCF services using unit test by just referencing your service implementation (see Ploeh’s Blog) You gain a lot of benefit if you use the WCF infra structure to test your services.
For Example, did you ever get the error message during integration test (or worse, production) because your message couldn’t be serialized because of a null value. This wouldn’t happen if your unit test were using WCF. Espacially when you have large messages with a lot of elements.
See Howard’s blog how to implement this.
raymondr .Net .Net Framework 3.5, MSTest, Unit Test, WCF
In the old days of ASMX webservices it was very easy to distribute the wsdl file of your service to other people, for example if you develop a service that’s not available to that person yet. The only thing you had to do was browse to http://myserver/mywebservice.asmx?wsdl and save the result of it. But nowadays the wsdl provided by your wcf service contains multiple files, the wsdl files uses import elements to include these file in the wsdl.
If you use svcutil.exe, wsdl.exe or some other tool to create a webservice client and reference a webservice directly this doesn’t matter. But this week I had to distribute my wsdl file and my service isn’t published yet. The only option was to download the wsdl file and each included file by hand.
After some searching for a neat solution I found a blog post by Mike Hadlow for downloading a wsdl and all included files to local disc. His solution makes use of the DiscoveryClientProtocol class in the .Net framework. This piece of code downloads all files but leaves the references of the xsd files pointing to the original url of the service. But this was also easy to solve. The WriteAll method of the DiscoveryClientProtocol class also creates a information file with the original location and the new filename. The only thing that has to be done is to replace the original urls with their local values.
Wsdl Download Executable
Wsdl Download source code
raymondr .Net, Dev .Net Framework 3.5, WCF, wsdl
Curious why you unittest don’t log any messages using Log4Net? And you do have the configuration set in your app.config file? This is propably the result because your log4net config file isn’t deployed in the TestResult directory.
To enable Log4Net in your MSTest unittests :
- Add your Log4Net file to the deployment files
- Read the Log4Net configuration in your Assembly Initialize method (see below)
Add The Log4Net file to the deployment files
- Double click on the LocalTestRun.testrunconfig File
- Select deployment items
- Click Add
- Browse to your Log4Net config file.
(This can be the same file as in your web or Windows project. In this way you use the same configuration as in your normal project.)
Reading Log4Net configuration
You can read the Log4Net configuration in you class initialization method but then you will have to put this information in every unittest class in you assembly. A better way is to put this code in the AssemblyInitialize method. The AssemblyInitialize method is just like the ClassInitialize method but this method will be executed only once before the execution of the unittest in your assembly.
Create a new class, for example TestAssemblyInit.cs and add the code below
[AssemblyInitialize()]
public static void MyTestInitialize(TestContext testContext)
{
// Take care the log4net.config file is added to the deployment files of the testconfig
FileInfo fileInfo;
string fullPath = Path.Combine(System.Environment.CurrentDirectory, "log4net.config");
fileInfo = new FileInfo(fullPath);
// Reload the configuration
log4net.Config.XmlConfigurator.Configure(fileInfo);
// test to see if it works
Log.Info("check");
}
raymondr .Net, Dev, Uncategorized Log4Net, MSTest, Unit Test
After running Dot Net Nuke for a while, I changed my blog to WordPress. It’s also an open source initiative but this one is running on a different platform I normaly work with. But that could be fun too.
I used DNN just for blogging, but the blog modules just don’t offer the functionality WordPress does, and after re-writing some blogposts again I thought I would be nice to try something else.
raymondr Uncategorized
After installing the .Net 3.5 sp1 framework update on my Team Foundation Server, I noticed the hard way my TFS wasn’t working any more. Thanks to a little line below the error I noticed my TFS server was configured to ASP.Net 1.1 instead of ASP.Net 2.0. After changing this back to 2.0 (for every site and virtual directory!) every things works smooth again.
raymondr .Net, Dev .Net Framework 3.5, TFS
Java development is some while ago for me, but just got a new Android device so I installed Eclipse and the Android SDK on my Linux machine. But what you gonna develop? Well I couldn’t find a app on the Android market to control my SoundBridge device. So that will be my first project. Don’t expect to many results in the near future because I have currently a lack of spare time.
But on of the first things I ran into was an unknown IO error. The Soundbridge uses a kind of telnet interface to interact with, but I just could not open a connection. After some research I founded out, the application doesn’t have any permission to access the network by default. To grant the application network access you have to declare it in the AndroidManifest.xml file.
<uses-permission android:name="android.permission.INTERNET" />
It’s fully understandable, but another error message would be much more informative.
raymondr Android, Dev Android
createUnfortunaly Silverlight 2 didn’t ship with any utility to generate a proxy class from the command line. Generating service proxy classes as service reference isn’t the way to go for me. Michael Giagnocavo wrote a little utility that makes use of a dll shiped with Silverlight to generate a proxy gut this one fails for me when I generate a little more complex proxy then HelloWorld. for example when I use multiple namespaces etc.
Read more…
raymondr .Net, Dev Silverlight 2.0, SVCUtil, WCF
The Entity Framework makes it very simple to implement Optimistic Concurrency Control (OCC). To use this feature in combination with a disconnected application (Website/webservices), the recommend practice is to send both the original and the updated values of the object. This causes much larger network requests and could be done much more elegant.
How to use Optimistic Concurrency Control in ADO.Net Entity Framework using Webservices or WCF
Optimistic Concurrency Control in Entity framework
For using OCC in the Entity Framework you’ve got 2 options:
- using Stored Procedures
- Set the Concurrency Property of an object.
Read more…
raymondr .Net, Dev .Net Framework 3.5, Entity Framework, WCF