Favorite Visual Studio Extensions

by Aref Tue, April 08 2014 10:09

Here are some of my favorite Visual Studio Extensions

Web Essentials 

http://visualstudiogallery.msdn.microsoft.com/56633663-6799-41d7-9df7-0f2a504ca361?SRC=VSIDE

Adds many useful features to Visual Studio for web developers. Web Essentials extends Visual Studio 2013 with a lot of new features that web developers have been missing for many years. If you ever write CSS, HTML, JavaScript, Markdown, TypeScript, CoffeeScript or LESS, then you will find many useful features that make your life as a developer easier. See more here: http://vswebessentials.com/features/general

CodeMaid

http://www.codemaid.net/

An open source visual studio extension to cleanup, dig through and simplify our C#, C++, F#, VB, XAML, XML, ASP, HTML, CSS, LESS, JavaScript and TypeScript coding.

CssCop - FxCop for Stylesheets

http://visualstudiogallery.msdn.microsoft.com/a921b98e-9430-4be2-bf53-1169e12bdb50

CSSCop helps you write better and more browser compatible stylesheets. It uses the CSS Lint (csslint.net) rules engine and is completely customizable.

Mexedge Stylesheet Extension

http://visualstudiogallery.msdn.microsoft.com/b6dd8050-77fa-4dba-998f-dabdd255d96d

This Visual Studio extension allows you to visualize in a tree view form the structure of your css files right into your Solution Explorer, from media directive to classes, ids, types and declarations as well as pseudos. Like any other solution explorer extension, it also supp...

Unit Test Generator

http://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7

Generates unit test code for methods in classes under test.

SlowCheetah - XML Transforms

http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

This package enables you to transform your app.config or any other XML file based on the build configuration. It also adds additional tooling to help you create XML transforms.. Written by: Sayed Ibrahim Hashimi, Chuck England and Bill Hiebert

Cobisi Routing Assistant

http://visualstudiogallery.msdn.microsoft.com/f0589156-a8e6-47db-8bac-90f01ca6b8a3

Browse, define, match and filter ASP.NET MVC routes within ASP.NET applications and web sites.

 

Please share your favorite extensions and add-ins via comments.

Tags: ,

Technology | Visual Studio

WCF for the uninitiated – Configuring and Hosting your Services

by Aref Tue, December 03 2013 18:34

Endpoints, endpoints and endpoints. Here we will cover some different ways you can configure the endpoints for your services.

Communications Endpoints

Here we will discuss how to configure the service endpoints for different forms of communications. As discussed in the previous post on WCF, configurations are managed through the app.config for the service project. In the previous post, we have seen how we can right-click on the app.config and then click on ‘Edit WCF Configuration’ to configure your service, endpoints and behavior.

If we were to examine the app.config by opening it as an XML document, we will find that after completing the last exercise, we have 2 endpoints. One for the basic http deployment and the other for the metadata exchange.

Each endpoint has three attributes associated with it.

v  Address – the network address, where is the service located

v  Binding – how are we going to communicate with the service such as transport and WS* protocols

v  Contract – describes what the message must provide and contain (types and operations).

Below the endpoints definition, in the app.config there is also a <host><baseAddresses><add baseAddress=”….”>… defined that is the base address for all our services that have been defined. The address attribute of an endpoint simply gets added to the base address.

You can add additional endpoints, such as those using another communication protocol such as TCP or Named Pipes, to your service through the Microsoft Service Configuration Editor Dialog box, after you have deployed your service. You can even make these changes directly in your app.config.

Configuring Service Behaviors

We can add different behaviors to our services. For instance you can expose the WSDL / metadata of your service through a Http Get operation by enabling that behavior.

1.       Create the behavior. In the Microsoft Service Configuration Editor Dialog box, Advanced, Service Behaviors and adding or editing an existing behavior. I have marked the HttpGetEnabled to True, provided a URL for the HttpGetUrl attribute and named it Metadata.

2.       Use the behavior. Now in the Services node, I locate the service and provide the behavior called Metadata to the BehaviorConfiguration attribute and saved the dialog box.

3.       Upon hosting the service, the WSDL will now be available at the URL provided in Step 1 above. A client can then generate a proxy from this WSDL.

Configuring Service Bindings

We can also configure bindings for our services to support the various WS* extensions such as Security, Reliable Messaging, etc. To do this, the easiest way is to use the Microsoft Service Configuration Editor Dialog box, go to the Bindings node, right-click and add or edit the appropriate binding and then go to your service endpoint, and in the General pane on the right, associate the binding configuration you just created for the BindingConfiguration attribute.

Hosting your service in IIS

1.       Start by adding a new Web Site project to the solution.

2.       Choose the WCF Template and we’ll call it the GetCurrentTimeSite

3.       Now, delete the Service.cs and IService.cs from the newly created Web Site project and Add a REFERENCE to the web service project.

4.       This will add the service library dll in the Bin directory.

5.       Next rename the Service.svc to something more meaningful such as GetCurrentTime.svc

6.       Next edit the .svc file and change the Service attribute to the fully qualified name, in our case, TutorialService.CurrentTimeService

7.       Further, delete the codebehind attribute and its value.

8.       Now, we need to configure the service and its endpoint(s). Launch the web.config Microsoft Service Configuration Editor Dialog box for the web site,

9.       For the Services node, click on Create a new Service and provide it the service implementation and the contract interface by browsing to the dll in the Bin folder from within the wizard.

10.   Now test this out by right-clicking on the .svc file and selecting View in Browser.

11.   You will see the documentation for the newly created service in a browser window.

12.   To test, go to a command prompt and type in> wcftestclient [address of the service from the documentation. should end in .svc]

13.   If all works well, go to the IIS management tool and create a new application under one of the sites.

14.   Now map this new application to a physical path of the service site (GetCurrentTimeSite) in our case.

15.   Now your service should be available, hosted within IIS.

Tags: , ,

IIS | Visual Studio | WCF

WCF for the uninitiated

by Aref Tue, December 03 2013 14:41

This assumes that you have the basic idea behind what a service is and the high level design assumptions. Basically that you understand that a service is a contract between the service provider to the consumer. The contract is internally represented as an interface and that the service can then be exposed and consumed using different mechanisms (transport, address, etc.) known as endpoints. In this exercise we will create a basic service that takes a caller’s name and gives them a user friendly message indicating the current system date and time.

Create a new service library project

1.       Create new project, use WCF / Service Library template as shown below.

2.       Delete the Service1.cs and IService1.cs that get created by default.

3.       Now let us get to create our service to provide the current system date and time as string. This service will take the requester’s name as an input parameter and return a friendly message with the current system date and time.

a.       Create a new Class called CurrentTime for the message contract as shown below and annotate it with [DataContract]. You will have to import the System.Runtime.Serialization namespace to resolve the [DataContract].

b.      Next we will decide which fields to include in the data contract and annotate those with the [DataMember] attribute. Since we have only one field, “RequestersName”, that is what we will annotate.

4.       Now, we will add a service contract to work with the Data Contract. So, let us add a new interface called, ICurrentTimeService.cs and add it to the project.

5.       In here, we will define our contract operations. In our case, we simply want to provide the user with a way to get the current date and time, so we shall call this GetCurrentTime as shown below. For WCF to understand this as a service contract, we will annotate the ICurrentTimeService interface with [ServiceContract]. For ServiceContract to be recognized, you will need to reference the System.ServiceModel namespace.

6.       Next we need to tell WCF which methods (operations) in our service contract we wish to include. We do this by annotating the method definition with [OperationContract]. Since we have only 1 operation, GetCurrentTime, we will go ahead and annotate it as such.

7.       Next we will add the actual implementation of the Service Contract described above. To do this, let us create a new class called CurrentTimeService that implements ICurrentTimeService as shown below.

8.       We will also implement the GetCurrentTime method in the service to actually return a friendly message with the current date and time.

9.       Next, we will describe some service behavior for our service implementation. To do this, we will annotate the service class, the CurrentTimeService class with [ServiceBehavior(…)] attribute to specify how our service will be managed by the WCF framework runtime. We will specify the following:

a.       ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall) to Single. We could have also specified as Single (much like a singleton) or PerSession (create once per user (could be calling application) session. This will cause the WCF runtime to create only a single instance of our service at runtime for each call.

10.   Now, how do we communicate with our new service? To do this we have to create an endpoint that represents a particular character set on how we are to communicate with our service.

11.   Now, we shall visit our friend, the WCF App.Config file which is already created for us.

a.       Right-click on the App.config file and choose,

Edit WCF Configuration.

b.      In the modal dialog that appears, start from the top left, Services, and click on the first service, select it in the right hand pane and click on the … elipses to locate our service implementation, TutorialService.CurrentTimeService under Bin\Debug as shown in the diagram below. (Note, if you don’t find anything under Bin\Debug, make sure you build your project).

c.       Next, expand the service to locate the endpoints, expand the endpoints tree and choose the first empty endpoint. Select the Contract in the right hand pane of the dialog box, click on the … elipses and browse to Bin\Debug and select the contract interface as shown below.

d.      Next, let us look at the metadata exchange endpoint. Click on the main Services node locate, on the right pane, notice the metadata exchange endpoint denoted by the address: mex as shown below.

12.   Now, it is time to test the service. Hit F5 and the WCF Test Client will be launched that you can use to test your newly created service as shown below.

Below are the listings for the classes and interface described above.


 

CurrentTime.cs

 

ICurrentTimeService.cs

 

CurrentTimeService.cs

Tags: , , ,

Visual Studio | WCF