skip to Main Content

WCF Client Error “The connection was closed unexpectedly” Calling Java/WebSphere 7 Web Service

If you get the following exception calling a WebSphere web service from your .NET WCF Client (service reference):

System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly. —>  System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.

Try adding this code before the service call:

System.Net.ServicePointManager.Expect100Continue = false;

More info on the 100-Continue behavior from MSDN.

My Multiple-Monitor Programming Setup

In my opinion, the top three hardware items that help maximize programmer productivity are sufficient RAM, multiple monitors, and a fast multi-core CPU. For RAM, try to have at least 2GB for Visual Studio development, especially if you have additional applications such as Resharper, a local SQL Server instance, IIS, etc. Remember that on Windows XP or Vista 32-bit, the maximum usable RAM is limited to about 3.2 GB or so.

My current company-provided laptop, which I must perform most programming activities on, is a Core 2 Duo 2.4 Ghz. It is satisfactory for what I am doing. Given the choice however, I would go for a quad-core CPU desktop. Desktop usually has faster drives, better video cards, etc. And the additional cores allow for smooth multitasking and better performance when using virtual machines.

image

Plenty of RAM and multiple fast CPU cores will keep the waiting down to a minimum. Now you need to give yourself the ability to see all of those things that you have going on. Research has demonstrated that multiple monitors increase productivity. For most programmers, I would recommend two monitors. Adding that second monitor is a relatively inexpensive affair. Most laptops or desktop video cards has built-in support for a second monitor so all you have to do is getting that second LCD, which cost very little these days compared to three years ago. The third monitor and beyond is where things start to get complicated. You either have to install a second video card, or use a second PC/laptop in conjunction with a software application named MaxiVista. Unless you have spare monitors sitting around, I think the return on investment starts to diminish greatly beyond two monitors.

Another way to use that third or fourth monitor is to simply attach them to additional computers. Sure, you won’t be able to control all those monitors with the same mouse and keyboard but this setup is not without advantages:

  • When the first computer is rebooting or not responding, you still have a fully functioning computer.
  • The screens on the second computer are not using CPU/memory resources on the first computer.

My 5-Monitor Setup

I work from home most of the time and on my desk, there are five monitors, hooked up to three laptops. I know… it’s over the top but it’s not like I bought all of these laptops/monitors specifically for this setup. The second laptop is my personal laptop. The third one is another old personal laptop that would otherwise would be sitting around gathering dust. I might as well put them all to use. Here’s how the monitors are arranged:

image

The main laptop is hooked up to monitor #1, an ASUS 24″ running at 1920×1080 resolution and monitor #2, the main laptop’s built-in 15.4-inch LCD running at 1680×1050. I spend most of my time on these two monitors. The ASUS 24″ is great for programming/debugging and is where I normally park Visual Studio 2008 or Rational Software Architect. If you can get one with more vertical resolution (such as 1920×1200), that’s even better.

Visual Studio

The extra width on the main monitor allows me to permanently open supporting panes like Solution Explorer that I otherwise would configure to “auto hide”. Note where I have my Start menu: on the right edge of the main monitor. This gives me more vertical space so I can see more code without scrolling. The additional benefits are that more opened windows can fit on the task bar, and that I don’t have to move the mouse as much to access the start menu.

The built-in laptop monitor (#2) is where I have miscellaneous supporting windows such as rolling logs, instant messaging client, email client, documents, etc.

For taking notes, I use Microsoft OneNote and since it’s not installed on my company PC, I use my own laptop for it. This laptop is monitor #3, sitting to the left of the main monitor. Monitors #4 and #5 are used once in a while to display server logs, various server telnet and remote desktop connections, and anything I don’t need to control often.

Update 2/25/2008 – Synergy

Rohan kindly pointed out to me a free keyboard/mouse sharing utility called Synergy. You should give this a try if you have multiple computers on your desk. Synergy lets you use a single keyboard/mouse to control multiple computers, running multiple operating systems. Additional features include clipboard sharing, screen saver, and single password login. The configuration is not the most intuitive but once you have everything set up correctly, it works like a charm.

I now can control all three laptops and 5 monitors with one mouse/keyboard combo! Very nice.

Synergy animation

Learning Java from a .NET Developer’s Perspective

I feel like I am discovering a whole new world. For my latest project, I have to do a lot of stuff in Java (1.6). While I am familiar with Java the language, I am a total newbie when it comes to Java related technologies, frameworks, and tools. Some of the specific Java technologies and tools I am using are JAXB/JAX-WS web services, Spring Framework, WebSphere Application Server, Maven, Rational Software Architect/Eclipse IDE.

Java Learning Resources

Here are some of the resources I found very useful while learning Java and related technologies in the past several weeks:

Portals

  • Java.sun.com – From the creator of Java itself.
  • Dzone – It’s like DotNetKicks but has everything including Java stuff.
  • IBM Redbooks – Tons of reference materials and everything is free.
  • developerWorks: IBM’s version of MSDN. There is a busy community section with forums as well.
  • Safari Books Online offers on-demand digital access to reference books. It’s not free, but it’s a great resource if you can read lots of books in a short time. Subscribe to their unlimited account and read all the books you want for a month. Remember to cancel before the month is over. Also remember that IBM Redbooks are free on the Redbooks site. Don’t waste your Safari points on Redbooks. And even if you have an unlimited Safari account, IBM’s site is still better because it offers PDFs.

Java

Web Services

Spring Framework

Eclipse IDE, Rational Software Developer/Architect

Misc

C# Features I Wish Java Has

I am sure Microsoft was pretty much thinking about Java when they created C#. The Java language itself it very similar to C# in terms of syntax, keywords, and use of punctuations such as semicolons and braces. I have found that most language features in C# have equivalents in Java. However, there are a few notable exceptions which I particularly miss:

  • Code regions – I use code regions extensively in C#. Eclipse does support code outlining but it’s only for existing code structures (methods) and is not nearly as flexible as c# regions.
  • Properties – Java only has fields and methods. “Properties” are implemented as get* and set* methods. I really miss properties, especially after typing 10 getters and setters in a row.
  • var keyword – Another small but very nice feature in C# that helps make code more compact and reduce typing.
  • Verbatim (@) strings – Very handy for regular expressions and other string literals that contain lots of escape characters.

Java is still evolving. Here’s hoping that some of the above features will make it into the next version of the language.

Wrap Your Unit Tests in Transactions

I have found that the key to writing good unit tests that interact with the database is making sure that the data is in a known state before and after the test. System.Transactions makes this very easy. All you have to do is wrap your unit test inside a TransactionScope and rollback at the end.

For example, in the test below, I am testing the update feature of my Customer data access class. To make sure I have a customer to update, I create it myself at the start of test, then I update it. At the end, scope.dispose() rolls back the whole thing. The database should look exactly like it was before my test.

[TestMethod]
public void CanUpdateCustomer()
{
    using (TransactionScope scope = new TransactionScope) {
        Customer customer = CreateTestCustomer();
        customerDac.saveCustomer(customer);
 
        customer.Phone1 = "804-555-1212";
        customerDac.updateCustomer(customer);
 
        // TODO: verify that update works
 
        scope.Dispose(); // roll back
    }
}

Here are a few more tips I have for unit tests that interact with the database:

  • Maintain scripts to create/rebuild a starting-point database. The starting-point database may contain some data such as lookup data, codes, etc. If your unit tests work correctly, the database will stay the same across tests. With the rebuild scripts, you can easily rebuild in the case of other mishaps or a bug in one of the unit tests causing corrupt data.
  • If you need to create a database record that doesn’t have an auto-generated key, use a random key to minimize the chance that your test will collide with another test running somewhere else. Seed your random generator with Environment.TickCount or a hash code of the machine name or user name.
  • With my Transactional File Manager, you can also restore the state of the file system in addition to the database. Transactional File Manager is great at automatically cleaning up any temporary files you create in your unit tests.
  • Don’t assume your code is the only thing that is touching the database. If the count of records in a table is x, it won’t necessarily be x + 1 after you add a new record to the table. Somebody else may have added to or deleted from the table while your test is running.

For Java programmers, try using Spring TestContext Framework. It’s a bit more complicated to use but it works just as well.

Back To Top