August 13, 2008

WCF Debugging in Visual Studio 2008

Debugging WCF Services is a lot easier in Visual Studio 2008. There is a WCF Service Host built-in to privately host WCF Services, as well as a built-in client that can be used as a test harness, and to view XML Requests and Responses. Here’s a quick walk-through on how to set up a quick sample WCF service, execute it using the client utility, and to create a simple console app that calls the service that will allow you to debug both client and server code without going through hosting the service in IIS, attaching to process, etc…
First, create a new WCF Service Project (File…New…Project -> Expand C#..WCF -> Select WCF Service Library)




The newly created project has a sample method GetData(int) that simply takes in an int, and returns a string. That’s the method we’ll be using. Now right-click the App.config file and select Edit WCF Configuration. This brings up a GUI view of the XML config file. Click the first “(Empty Name)” link that uses the binding wsHttpBinding.




This allows you to edit the Service Endpoint. Give it a name.




Save the configuration, now hit f5 to run the app. The WCF Test Client will launch. Double-click the GetData() method.




This brings up a test harness that will allow you to test the method. Enter a value for the Request Value and click Invoke. In a few seconds, the Response Value should display “You entered: [number]”.




OK, Now we’re ready to create a console client application that will call our service, and allow us to debug through client and server code. Add a new Console Application to the solution.




Right-click the newly created console app and select “Add Service Reference”. This brings up a dialog box that allows you to add a service reference. Click the down arrow next to the Discover button and select “Services in Solution”. Select your service in the dropdown and click Go, when it appears under Services, click OK.




Now go into the Main method of Program.cs in your console app. Add the following call to the referenced service:

ServiceReference1.Service1Client sc = new Service1Client();
Console.WriteLine(sc.GetData(11));

And set a breakpoint at Console.WriteLine.




Now you’re ready to start debugging. First run the service (F5), then start a new debugging instance of the console app. The debugger should now be stopped at your breakpoint in the console app. Step into the code (F11) and you will step through the GetData method in your service code.

When you finish stepping through your code, the console should display the return value.



A full Silverlight presentation of WCF Debugging is also available here.

Share |

August 11, 2008

Excel Extend series - all rows

I recently had to deal with very large (300K+ rows) Excel spreadsheets. I needed to add an additional column based on calculations of other existing columns. I was familiar with the extend series functionality of Excel for extrapolating a function over multiple rows, but what a pain to drag for 300,000 rows. There has to be an easier way to apply a function to all rows. So I Googled and found a nice easy way to Extend Series to all rows, just double-click the square in the bottom right corner of the column with the function applied and presto, the calculation is applied to all rows in the spreadsheet:

Create the function in row 1


You can extend the function to subsequent rows by dragging the square in the bottom right corner of the selected cell...



...or just double-click the black square, and the function is extended all the way to the last cell ie; the 17th row function is =a17*b17.



Special thanks to Phil for his help.

Share |