Blog - Title

Visual Studio 2013 Current Status

  • The Ultimate Visual Studio Tips and Tricks Blog

    Automatically Check for Updates to Visual Studio 11

    • 2 Comments

    There is an update to Visual Studio 11 that came out in early April that is available.  You can find the details here:

    http://support.microsoft.com/kb/2677574

     

    If you haven’t been playing with Visual Studio 11 yet, I strongly encourage you to get it today.  You can download it from here:

    http://www.microsoft.com/visualstudio/11/en-us/downloads

     

    When you DO have it one of the first things you should do is turn on automatic checking for updates to extensions found at Tools | Options | Environment | Extension Manager:

    image

     

    Not only will this make sure you are notified about the latest and greatest version of your favorite extensions but it will also enable notification of updates to Visual Studio!  We are now pushing updates to the IDE as extension-like elements. When you enable this feature, every time you start Visual Studio you will see a message whenever there is an update to Visual Studio that looks like this:

    image

     

    You can click on the bubble or, to get to updates manually, go to Tools | Options | Extension Manager | Updates | Product Updates:

    image

     

    You will see the update(s) available and can then click on the Update button for the items you want. In this case, when I clicked on update for the April 2012 fix for VS11, I received the download dialog:

    image

     

    Selecting Run began the installation process:

    image

     

    It finished smoothly and Visual Studio was updated easily.

     

    Go out there and update your version of Visual Studio 11 if you haven’t done it already so you can get the most up-to-date goodies!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Make Selection Uppercase or Lowercase

    • 1 Comments

    Keyboard:  CTRL + SHIFT + U (upper); CTRL + U (lower)
    Menu:  Edit -> Advanced -> Make Uppercase; Edit -> Advanced -> Make Lowercase
    Command:  Edit.MakeUppercase; Edit.MakeLowercase
    Versions:  2008,2010
    Published:  4/10/2010
    Code:  vstipEdit0044

     

    Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!

     

    Okay, so let's say you have some text (a variable, maybe?)

     image 

     

    and you need to do some case-changing action on it.  Plus, there is a crazy guy holding several people hostage and threatening to dip them in boiling chocolate unless you do it fast.  What do you do?  No Problem!  You just select the word and press CTRL + SHIFT + U to make it uppercase

    image 

     

    or if the evil guy isn't satisfied you can always make it lowercase by pressing CTRL + U

     image

     

    And now you have saved the day!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Collapsing Your Code with Outlining

    • 14 Comments

    Keyboard:  CTRL + M, CTRL + M
    Menu:  Edit -> Outlining -> Toggle Outlining Expansion
    Command:  Edit.ToggleOutliningExpansion
    Versions:  2008,2010
    Published:  3/15/2010
    Code:  vstipEdit0029

     

    By default, Outlining is enabled in Visual Studio.  It's the line you see with the boxes to indicate the status of the area (collapsed or expanded):

    image

     

    You can collapse areas of code to get them out of your way so you can focus on other areas.  There are four ways to do it:

    1. Click on the minus sign to collapse an area of code:

      image

      NOTE:  In VS2010 it now highlights the area that will be collapsed as seen here.  A very cool feature.  If you don't like the highlighting color you can go to Tools -> Options -> Environment -> Fonts and Colors -> Collapsible Region to change it.

    2. VS2010 ONLY:  Click ANYWHERE on the vertical line in the highlighted region.  In other words, you can now collapse a region from anywhere in that region:
      image 
    3. Click anywhere in the area to be collapsed and hit CTRL + M, CTRL + M
    4. Click anywhere in the area to be collapsed and go to Edit -> Outlining -> Toggle Outlining Expansion on the Menu Bar

     

    Once collapsed, the code area will look like this:

    image

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013 Preview: Enhanced Scroll Bar

    • 16 Comments

    Visual Studio 2013 has another great new feature: enhanced scroll bar functionality. The new scroll bar will show cursor location, breakpoints, and much more! Let’s take a look.

    5-17-2012 12-51-16 PM

     

     

    Power Tools

    Before we begin I want to address where some of the new features in VS2013 are coming from. In Visual Studio 2013 many of the new features we put into the product were actually introduced via the Productivity Power Tools for Visual Studio 2012. This is an ongoing trend and you will see that many of the new features from future versions will come directly from the Power Tools. If you are still on 2012 you can get a lot of the newest functionality by installing the Visual Studio 2012 Power Tools which can be found here:

    http://visualstudiogallery.msdn.microsoft.com/3a96a4dc-ba9c-4589-92c5-640e07332afd

     

     

    Scroll Bar Options

    To really get a handle on the new scroll bar functionality the first thing you should do is Right Click on the vertical scroll bar and choose Scroll Bar Options:

    5-17-2012 11-57-37 AM

     

    You will see several settings that can be modified:

    5-17-2012 12-00-10 PM

    (NOTE: You can also get to this area by going to Tools | Options | Text Editor | All Languages | Scroll Bars)

     

     

    Show Scroll Bar

    5-17-2012 12-08-43 PM

    The first two options are pretty self-explanatory they will allow you to show or hide the scroll bars. For the most part you will leave these checked unless you have some special reason not to have them visible. 

     

    Display

    5-17-2012 12-12-18 PM

    The Display area allows you to turn on annotations that will show special items throughout the entire document within the scroll bar. This allows you, at a glance, to see where things like breakpoints and bookmarks are. We will look at these in the order you are most likely to encounter them but here is an example of the vertical scroll bar with annotations in it:

    5-17-2012 12-32-50 PM

     

     

    Show Caret Position

    5-17-2012 12-17-37 PM

    The first annotation you will most likely encounter is the caret position indicator. It simply shows the current position of the cursor with a blue line in the scroll bar.

     

     

    Show Changes

    5-17-2012 12-28-50 PM

    If you missed my blog post a couple of years ago on tracking changes in the editor, this is a good time to read it. You can find the post here:

    http://blogs.msdn.com/b/zainnab/archive/2010/04/14/track-changes-in-the-editor-vstipedit0048.aspx

     

    The Show Changes option simply shows the changes within it so you can see modifications at a glance for the entire document.

     

     

    Show Marks

    This options is fairly broad and covers several types of marks that can appear in code. Most notably this will show breakpoints:

    5-17-2012 12-42-29 PM

     

    Additionally, this will also show things like Bookmarks:

    5-17-2012 12-44-01 PM

     

     

    Show Errors

    The final indicator is arguably one of the most important. It shows any syntax errors the editor is aware of:

    5-17-2012 12-46-58 PM

     

    This let’s you quickly see where there are errors that need to be fixed before you compile your code.

     

     

    Behavior

    There are two behavior options for the vertical scroll bar: bar mode and map mode. So far everything we have seen is the traditional bar mode for the scroll bar. Now we will switch to map mode:

    5-17-2012 12-55-12 PM

     

    Map mode essentially turns your vertical scroll bar from this:

    5-17-2012 12-56-48 PM

     

    To this:

    5-17-2012 12-57-38 PM

     

     

    Source Overview

    Map mode is miniature look at your document so you can quickly get a feel for your code. There are four options for source overview when using map mode. I’ll show examples of the four views below. Of these the Off setting will be the most confusing until you see the Preview Tooltip in action so be patient.

     

    Wide

    5-17-2012 12-57-38 PM

     

    Medium

    5-17-2012 12-59-53 PM

     

    Narrow

    5-17-2012 1-00-50 PM

     

    Off

    5-17-2012 1-02-23 PM

     

     

    Preview Tooltip

    Regardless of which map mode view you use there is also an option to have the Preview Tooltip. Simply put your mouse pointer over any part of the vertical scroll bar and you will get a preview of the code at that position in the document:

    5-17-2012 1-09-33 PM

     

    Annotations

    All annotations previously mentioned also show up in map mode:

    5-17-2012 1-12-45 PM

     

     

    Go to a Specific Location on the Scroll Bar

    You basically have two options when you want to go to a specific location on the scroll bar. Let’s examine both ways.

     

    Left Click

    As long as you are in map mode:

    5-17-2012 2-39-51 AM

     

    You can simply LEFT CLICK any area on the scroll bar and you will jump to that location:

    5-17-2012 2-41-10 AM

     

    For this reason, I suggest, even if you don’t want the map, that you at least use map mode set to Off to get this functionality so you can quickly move around using the scroll bar:

    5-17-2012 2-44-42 AM

     

     

    Scroll Here

    Now that you have a solid base level of knowledge for this feature there is one more important item I want to show you: Scroll Here. If you find any place that is interesting to you in the vertical scroll bar and want to quickly go to that location you can simply Right Click the location and choose Scroll Here:

    5-17-2012 10-12-17 PM

     

    The new location will come into view so you can begin looking at the code:

    5-17-2012 10-13-50 PM

     

     

    Finally

    The enhanced vertical scroll bar is a great tool for developers to quickly see places of interest and to examine those locations. Try this feature out and see if you like it as much as I do. :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Code Clone Analysis

    • 5 Comments

    In my travels across the country, with my fellow Evangelist, Clint Edmonson, talking about Visual Studio we often come across great stories to tell. One of our favorite true stories is of a customer that had a web application running very slow. We ran code metrics against it and, sure enough, the Page_Load event had 9,000 lines of code in it.

     

    Naturally we were curious so we opened it up to see that it was basically the same if statement copied over and over. Apparently they needed to find out who was coming into the website in order to show customized content and the solution they came up with was this massive set of statements.

     

    For better or worse we have all had code that gets copied throughout our solutions. Until now there was no tool to tell us there were copies and, instead, we had to rely on other metrics to hopefully reveal any code smells that lead us to duplicates. Now, however, we have the new Code Clone Detection (aka Code Clone Analysis) feature.

     

    According to the documentation:

    Code clones are separate fragments of code that are very similar. They are a common phenomenon in an application that has been under development for some time. Clones make it hard to change your application because you have to find and update more than one fragment. Visual Studio can help you find code clones so that you can refactor them.”

    http://msdn.microsoft.com/en-us/library/hh205279%28v=vs.110%29.aspx

     

     

    Specific Clones

    You can find clones of specific code by selecting the segment you are interested then right click on the selection to choose Find Matching Clones in Solution from the context menu:

    image

     

    Visual Studio will search for code clones and produce the result in the new Code Clone Search Results window:

    image

     

    The original line of code is put in a group on its own and then all the matches are put into a different group. You can expand the groups to see the specific locations of the matches:

    image

     

    Also, you can double click on any entry in the list to go to the selection in your code file:

    image

     

     

    Solution Clones

    Besides looking for specific clones you can also look for code clones for the entire solution. To use this feature go to Analyze | Analyze Solution for Code Clones:

    image

     

    This creates a result set for the entire solution:

    image

     

    By default it groups and sorts the results by the strength of the match. Exact matches come first then those matches that may be close but not exact come next and so on. The terms you may see are Exact, Strong, Medium, and Weak.

     

     

    Reviewing Matches

    Once you have the result set, there are a couple of ways you can compare them against each other.

     

    Comparison Tools

    If you have a comparison tool configured you can Right-click on any item and select Compare from the shortcut menu:

    image

     

    You would know if you have this feature available by going to Tools | Options | Source Control | Team Foundation Server and click on Configure User Tools.

     

     

    Manual Comparison

    If you don’t have a comparison tool you can do manual comparisons between two entries in the list. If the clones are in different files then you can just double-click each entry and it will open the file as well as highlight the entry that is duplicated as mentioned earlier.

     
     

    What Is Found

    You are probably curious as to what is found by this tool. The heuristics for finding clones will find duplicates even if the following changes have happened:

    · Renamed identifiers

    · Insert and delete statements added

    · Rearranged statements

     

     

    What Is Not Found

    There are some rules for what is not found as well. I have taken this list from the documentation pretty much verbatim.

    · Type declarations are not compared. For example, if you have two classes with very similar sets of field declarations, they will not be reported as clones. Only statements in methods and property definitions are compared.

    · Analyze Solution for Code Clones will not find clones that are less than 10 statements long. However, you can apply Find matching clones in solution to shorter fragments.

    · Fragments with more than 40% changed tokens.

    · If a project contains a .codeclonesettings file, code elements that are defined in that project will not be searched if they are named in the Exclusions section of the .codeclonesettings file.

    · Some kinds of generated code are excluded:

    · *.designer.cs, *.designer.vb

    · InitializeComponent methods

     

     

    Code Clone Settings and Exclusions

    A settings file is available to configure this feature at the project level. Currently we have only announced the ability to do exclusions in the file but there will most likely be other elements that are added later on. The file is just XML with a .CODECLONESETTINGS extension. The only requirement for use is that the file exists in the top level directory of the project.

     

    The base elements consist of a CodeCloneSettings element with an Exclusions child:

    image

     

    Within the Exclusions element you can have the following children:

    <File>

    This element is used to indicate files that should be excluded from analysis. Path names can be absolute or relative and you can use wildcards as well. So, for example, to ignore all the C# text template files that have been put in their own directory (called MyTextTemplates) you might have the following:

    image

     

    <Namespace>, <Type>, and <FunctionName>

    You can also exclude namespaces, types, and functions. Just like files these items can use absolute names or names with wildcards in them. Here is an example of what it might look like:

    image

     

     

    Exclusion File Example

    In the Tailspin Toys sample there is some generated code in the TailSpin.SimpleSqlRepository project that is the bulk of the duplications:

    image

     

    When I run code analysis, this is the result:

    image

     

    Code clone analysis doesn’t automatically know to ignore text templates so I would create an XML file called TailSpinRepository.codeclonesettings and insert an entry like this:

    image

     

    Now if I run clone analysis again here is what I get:

    image

     

    As you can see the results are significantly less than the first time the analysis ran. It’s common to create several exclusions in different projects to weed out noise in the analysis results.

     

     

    Finally

    Code Clone Detection is a great new tool to add to your arsenal for improving code quality. Combined with Code Analysis and Code Metrics, this will help quickly find potential issues.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Reset All Your Development Settings

    • 2 Comments

    Menu:  Tools -> Import and Export Settings
    Command:  Tools.ImportandExport Settings
    Versions:  2008,2010
    Published:  7/16/2010
    Code:  vstipEnv0023

     

    In the final post dealing with the Import and Export Settings Wizard, we deal with the nuclear option-the "Reset all settings" option:

    image

     

    WARNING:  Use this at your own risk.  It WILL reset your settings and do things like reset your Toolbox thus getting rid of any custom tabs, code pieces, etc.. you have put in there.

     

    Clicking Next will give you the option to save your current settings.  YOU SHOULD ABSOLUTELY DO THIS:

    image

     

    The next screen let's you choose from the list of default settings:

    image

     

    Choose your default settings of choice and click "Finish".  It will run for a few minutes and reset all your settings.  This is definitely something you would do as a last resort and, remember, you can always bring your old settings back by importing the previous settings.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013 Preview: Code Map Debugger Integration

    • 12 Comments

    5-16-2012 12-48-10 PM

     

    Prologue

    The original Code Map was introduced in the product with Visual Studio 2012 Update 1. You need to read my original post before moving on:

    http://blogs.msdn.com/b/zainnab/archive/2013/02/07/visual-studio-2012-update-1-understanding-code-map.aspx

     

    My assessment at the time was that it was a good feature but had poor performance and didn’t really add much value relative to Dependency Graphs. With debugger integration however Code Maps have definitely come into their own and the performance is very good.

     

    Note: Code Map Debugger Integration is a feature in the Ultimate edition of Visual Studio.

     

     

     

    Code Map Debugger Integration

    Assuming you have a handle on Code Maps now let’s see how the debugger integration works. First, I’ll take the TailSpin Toys sample code and set a breakpoint within the code base (ShoppingCart.cs, line 61):

    5-16-2012 12-04-13 PM

     

     

    I’ll press F5 and add an item to my cart to trigger the debugger:

    5-16-2012 12-07-12 PM

     

     

    Ordinarily, we would step though the code and hope we remember how we got to a particular place. Those days are gone! Now we can turn on the Code Map feature while debugging:

    5-16-2012 12-12-27 PM

     

     

    You can also find this on the Menu Bar at Debug | Show Call Stack on Code Map:

    5-16-2012 12-13-37 PM

     

     

    You will see a Code Map in sync with the debugger at this point. You can create Code Maps in C#, VB, C++, JavaScript currently. Once activated all future debugging sessions will include a Code Map until you turn this feature off:

    5-16-2012 12-17-38 PM

     

     

    If we take a closer look at the current map, we can see that it shows how we arrived at the current call (the squares above the last AddItem call) and our current location (yellow arrow). Although the current location indicator is partially covering it, you can also see the breakpoint indicator:

    5-16-2012 12-27-35 PM

     

     

    Stepping through the code we see the map keeps updating so we don’t have to keep the path in our heads:

    5-16-2012 12-29-19 PM

     

     

    The Code Map will continue to update for our debugging session showing where we have been and where we currently are in the call stack:

    5-16-2012 12-35-58 PM

     

     

    The graphs can get quite large:

    5-16-2012 12-40-46 PM

     

     

    For this reason it’s important to use the map tools at your disposal. The context menu items when you Right Click any node are a great example of common tools:

    5-16-2012 12-45-23 PM

     

     

    You can Double Click any node to view the code from that location in the stack. A green arrow will indicate your current position:

    5-16-2012 12-54-27 PM

     

     

    If you happen to choose a node that isn’t part of the current active call stack then you will get a slightly different indicator:

    5-16-2012 12-57-41 PM

     

     

    When you stop debugging the Code Map will be preserved so you can save it if desired and keep a map of the code base you just went through. I think this is an exceptional addition to the debugging experience!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Preview Tab

    • 17 Comments

     

    Preview Tab Overview

    We all explore code and need to move quickly between files when examining code to get familiar with it or debugging or [insert file browsing scenario here]. In prior versions of Visual Studio you had to open a file to look at the contents which often resulted in many open files (tabs) when you were done. The Preview Tab eliminates the need to open files when browsing code. Most likely you’ll first encounter the Preview Tab when you are looking at files with Solution Explorer. When you click on a supported file type, you will see the contents of that file in the new preview tab (to the far right in the tab well):

    image

     

    If you click anywhere inside the file the tab will go from grey to purple to distinguish it from regular (blue) tabs:

    image

     

    Again, the point of the preview tab is to let you view the contents of a file without actually opening up a new tab in the tab well. As you look at different files the preview tab only shows the contents of the file you are currently on. This keeps the environment from getting cluttered with open tabs and allows you to focus on only those files that are interesting to you. Solution Explorer isn’t the only place you can use the preview feature. It turns up in several situations where you might need to look at file content. For example, when using Find in Files (CTRL + SHIFT + F) to locate information you will see the preview tab:

    image

     

     

    Promoting Previews

    At some point you may decide to promote the preview to an opened tab in the Tab Well so you can do additional work on the file or just keep it around for other purposes. There are a few ways you can make this happen.

     

    Click the Keep Open button

    Probably the least useful and and least likely technique you will use is to click on the tiny Keep Open button on the Preview Tab.  It’s not only useless it’s actually kind of annoying for some reason I can’t identify:

    image

     

    Double Click the File

    The most likely approach is you will just double click the file in Solution Explorer or whatever results dialog you happen to be in.

     

    Press CTRL + ALT + HOME

    With the cursor inside the file (the tab is purple), just press CTRL + ALT + HOME to open a tab for the file you are currently viewing.

     

    Change the File

    While previewing a file, if you make any change to the file it will automatically be promoted to an open tab so that you can make additional changes and do any other actions you need to perform.

     

    Click the Preview Selected Items button

    Another button is useless and a waste of space on the Solution Explorer toolbar is the Preview Selected Items button.  You can click it to preview the current file and its only use that I can find is if you turn off single clicking a file to preview it (see below).  Also the tooltip would lead you to believe that you can select multiple files and preview them.  Nope.  Doesn’t work.  Don’t waste your time with this button.

    image

     

     

    Turning Preview Off

    To see the options you have for using the preview feature, just type preview in Quick Launch (CTRL + Q) and click Environment -> Tabs and Windows:

    image

     

    This will take you to Tools | Options | Environment | Tabs and Windows:

    image

     

     

    To turn off the preview feature (NOT suggested unless you are having performance issues with it) uncheck the Allow New Files to be Opened in the Preview Tab option. Also notice you can decide if a single click open the files in for preview in Solution Explorer and Find dialogs. For Solution Explorer you can use ALT to prevent a file from being previewed when you click on it. While I see the value in using ALT to prevent preview from happening. I haven’t yet found any reason for turning off the single-click option as it, in effect, forces you to use the Preview Selected Items button which is a lot of extra work and kind of defeats the purpose of the feature.

     

     

    Finally

    The Preview Tab is one of my top two favorite features in Visual Studio 2012 (the other one being project round-tripping).  You definitely want to leverage this feature to make your life easier.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Creating, Configuring, and Consuming a WCF Service in IIS 7

    • 10 Comments

    After much delay, here are the goods :)

     

    The goal here is to show how to create a basic WCF service that can be hosted in IIS7 and will kick over to other protocols using Windows Activation Service (WAS) as needed.  Your choice of language doesn't matter for this one and I will show code for C# and VB.  And awaaaaaaay we go...

     

     

    1. Start up Visual Studio by running it as Administrator

      image
    2. Begin creating a new Web Site

      image
    3. Feel free to pick your language of choice, for this demo I will call the services CoolServiceCS and CoolServiceVB respectively

      image
    4. Press F5 to build and run the application just to make sure all is well so far, you will get the obligatory error for debugging, just click OK:

      image
    5. You should ultimately see a web page that has something like this:

      image
    6. Close the service web page and let's see if IIS7 is aware of this service
    7. Go to the IIS Manager

      image

      image
    8. Expand the tree and, under "Default Web Site", you should see your service.

      image
    9. Okay!  So far everything seems to be going well.  Now let's take a quick peek at the service in Visual Studio to verify that it is, in fact, using HTTP to communicate.
    10. There are a couple of ways we can do this:  One way is to just open up Web.config and scroll to the <services> element:

      image
    11. Another way is to right-click on your Web.config and choose "Edit WCF Configuration..."
      SPECIAL NOTE:  There seems to be a "feature" that makes this not show up initially.  This is usually "fixed" by simply going to Tools...WCF Service Configuration Editor
      The funny thing is you don't appear to have to actually use this tool just open it and close it then you can right-click Web.config to get the editor option.  Weird.

      image
    12. If you expand the Service area and look at the Endpoints, you can see that wsHTTPBinding is used.  Once you have verified, close this dialog box.

      image
    13. The only thing I wish here is that the endpoints would be "automagically" named for us (we could always change the names) but, sadly, that is not the case.
    14. At this point we have created our service, run it, verified it is in IIS, and verified it uses wsHTTPBinding.  Now we need to create a client to consume the service.
    15. In Visual Studio, right-click on your Solution and choose Add New Project...

      image
    16. Let's use a Console Application for our client this time around.  Make sure to use your language of choice.

      image
    17. Call the application "CoolServiceClientVB" or "CoolServiceClientCS" as appropriate then click on OK.

      image
    18. Set the new project as the Startup Project.  

      image
    19. Now we need to right-click on the project and choose Add Service Reference...

      image
    20. The new service dialog is very cool and will find services in your solution if you just click on Discover --go for it! 

      image
    21. Leave all other settings as they are and click on OK.  You should see your reference in Solution Explorer.

      image
    22. Now let's crank a little code to actually use this service (finally!) heheh...
    23. Open up Module1.vb or Program.cs and put the following code in:

      VB:
    24. Sub Main()
             Dim myService As New ServiceReference1.ServiceClient()

             Console.WriteLine(myService.GetData(33).ToString())

             Console.ReadKey()
         End Sub

      CS:

      static void Main(string[] args)
              {
                  ServiceReference1.ServiceClient myService =
                      new CoolServiceClientCS.ServiceReference1.ServiceClient();

                  Console.WriteLine(myService.GetData(33).ToString());

                  Console.ReadKey();
              }

    25. This should look pretty straightforward.  We are calling one of the sample operations that are available with our WCF Service and then use ReadKey() to pause when we run the app.
    26. Press F5 to run this sucker and you should get this:

      image
    27. Press any key to continue.
    28. So we have a client and we have a service and we are all having a group hug.  Now what?  Well, now let's configure this puppy to use other protocols besides HTTP.  For this run, we will use TCP and Named Pipes.
    29. First, we have to configure Windows Process Activation Service (WAS) settings.  To learn more about WAS, go here:  http://msdn.microsoft.com/en-us/library/ms730158.aspx
    30. Assuming you're running Vista, we have to tell WAS that non-HTTP protocols can be used for activation.  If we were not using IIS to host this service we would also have had to tell it that HTTP activation is possible but fortunately IIS handles those details for us.  For more info on what we are doing here, you can check out this area http://msdn.microsoft.com/en-us/library/ms752218.aspx
    31. Go to Control Panel

      image
    32. Choose Programs

      image
    33. Now select Turn Windows Features On or Off

      image
    34. Go to the Microsoft .NET Framework 3.0 area and check the WCF Non-HTTP Activation.  NOTE:  Since this is my play machine, I also turned on WCF HTTP Activation as well but you don't have to unless you need it.

      image
    35. Click on OK; It may take a minute to install the needed files so be patient.  Go grab a drink or something, go on, you deserve it :)
    36. Next we have to configure the the web site to be bound to a TCP port for our activation to work.
    37. Open a command prompt with administrative privileges by right-clicking on the command prompt icon and choosing Run as Administrator

      image
    38. Copy and paste the following command into the command prompt area and press Enter

      %windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']
    39. The result should look similar to the following:

      image
    40. Now the Default Web Site is bound to TCP but we still need to allow TCP for our applicationCopy and paste the following into the command prompt area and press Enter:

      VB
      %windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/CoolServiceVB" /enabledProtocols:http,net.tcp

      CS
      %windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/CoolServiceCS" /enabledProtocols:http,net.tcp
    41. You should see something like this:

      image 
    42. Okay, the hard part is done.  We now have the Web Site and the application within the site configured for TCP.  We just need to tell the service to use TCP and then have the client use TCP to talk to the service.  Here we go!
    43. To configure the service, go to Visual Studio and Solution Explorer.  Now let's go to our service and right-click on Web.config to edit the WCF Configuration.  You may have to do that stupid Tools...WCF Service Configuration Editor workaround to get the context menu item to show up.  You may wonder why I just don't have you edit the XML directly and the answer is simple:  I'm all about easy and think that this way is easier for folks.

      image
    44. We need to make sure the service knows it can use TCP by creating a new endpoint.  Currently the only usable endpoint for communicating is HTTP but we are going to change that by right-clicking on endpoints under the Service and adding a new service endpoint.

      image
    45. Enter myTcpGoodness for the Name, choose netTcpBinding for the Binding, and enter IService for the Contract as seen here:

      image
    46. We also need to identify the BaseAddress for getting to our service.  Go to the Host area in the current dialog.

      image
    47. Under Base Address, click on New... and type in the following for the address then press enter:

      VB
      net.tcp://localhost/CoolServiceVB

      CS
      net.tcp://localhost/CoolServiceCS
    48. You should see something like this in the BaseAddress area:

      image
    49. Close the configuration dialog and you should be prompted to save changes.  Click Yes.

      image
    50. Let's make sure there are no errors.  Build the service by right-clicking on it and choosing Build Web Site.
    51. WOW!  We are on step 50 now.  Does it feel like your brain is going to explode like in the movie "Scanners"? http://www.imdb.com/title/tt0081455/  Just stay with me, we are almost done.
    52. At this point we could start configuring the client but I really like to run the service one last time to make sure there are no issues.  So this step is optional but suggested just to make sure everything is good with the service:  (1) Right-click on the Service.svc file and set it as the Start Page.  Right-click on the service project and choose Set as Startup Project.  Press F5 to run the application.  You should see the test page for the service.  If you do then all is well, if not go back and fix any issues.  Make sure to close the web page when you are done here and set the client application as the Start Up Project again.

      image
    53. Okay now on to the client.  Since we have updated the service we need to update the Service Reference on the client.  This is easily done.  Simply right-click on ServiceReference1 and choose Update Service Reference.

       image
    54. You should see this dialog flash by:

      image
    55. We are almost done.  Now we just have to tell the client what protocol to use based on the binding name.  Remember when you set the Name of the TCP Binding to myTcpGoodness?  Well you did that to make this step easier for us.  Go to Module1.vb or Program.cs to see the code for your client application.
    56. Now we will pass the name of the binding to use in the constructor so that the client uses the protocol we want.  Change the code for creating an instance of the service to this:

      VB
      Dim myService As New ServiceReference1.ServiceClient("myTcpGoodness")

      CS
    57. ServiceReference1.ServiceClient myService =
                      new CoolServiceClientCS.ServiceReference1.ServiceClient("myTcpGoodness");

    58. Now just run your client application and you should see the predictable result.

      image
    59. At this point you are probably asking if it is REALLY using TCP.  It's easy enough to test.  From your command prompt type in the following:
      DANGER:  DO NOT RUN THIS COMMAND ON A PRODUCTION MACHINE UNLESS YOU LIKE GETTING FIRED!

      net stop w3svc
    60. You should see this:

      image
    61. You have stopped IIS and killed HTTP as an option for communicating to our service.  Now run the client application again.  Does it work?  Then you are in business!
    62. We are done but if you want you can add net.pipe to be used just like you did with net.tcp and see if it works.  Play with it and enjoy!  Oh yeah, you might want to type in "net start w3svc" from the command prompt to get IIS running again.  :P
  • The Ultimate Visual Studio Tips and Tricks Blog

    Proposed Book Title

    • 32 Comments

    The new book is entering its final stages before we start work in earnest.  After much discussion internally we have finally come up with a potential title for the new book and I wanted to get your thoughts.  Let me preface this with the following:  We wanted to depart from the “tips and tricks” moniker for the book as we feel it doesn’t adequately portray what the book does (or should do at least).  With that said, the current thought on a title is (drum roll, please):

     

    Microsoft Visual Studio Productivity Handbook

     

    I really want your feedback on this one.  Does it suck?  Do you like it?  Tell me your thoughts…

     

    Z

Page 5 of 135 (1,345 items) «34567»