SOAP API in Visual Studio in C#

To create a api there are alot opporunities. Right now I prefer SOAP-APIs in Visual Studio because it is easy as possible to create such one.

I will do this with Visual Studio 2017 and a console-application, so nothing special:

For the example I googled for free SOAP-Webservice and got this one here that can handle some information about the BLZ:

http://www.thomas-bayer.com/axis2/services/BLZService?wsdl

To start in Visual Studio I add a reference like this:

  1. Rightclick in the solution explorer at references.
  2. Click “Add Service Reference”
  3. Click “Advanced…”
  4. Click “Add Web Reference…”
  5. Paste the URL and click on the arrow.
  6. Type in a name that specifies the webservice-name in your project.
  7. Click “Add Reference”.
  8. Done!

<

pre>This will add a folder to your projects called “Web References” and will add the service. Like this you will also get every object and method that you need. So I am able to write this code:

var BLZService = new OpenSOAPBLZService.BLZService();
 var Bank = BLZService.getBank("10070100");
 Console.WriteLine(Bank.bezeichnung + " - " + Bank.ort);
 Console.ReadLine();

 

Here we create a new object based on the service that we created, create a new bank object (which class is also created by the Add-Reference-Function) and show the bank description and the location of the bank in the console. So we get this out here:

visual studio shortcuts for debugging

First of all it is necessary to check out if you really want to debug while running the code. Anytime I look a developer starting the application I see him using the full debug-mode. The full debug-mode is slower and has some parts to do that you do not need if you do not want to debug actually. So first thing that I recommend to you is using [Ctrl + F5] to run the code. As well do not use a mouse. You are faster if you work with your keyboard as much as possible. If you really need to go to the debug mode you can use just [F5] do start the full-debug-mode. To set breakpoints you can use [F9].

While debugging you three basic ways to go throw the code. The first one is used by [F10] and will go over the next statement. To step into a function or a method you can use [F11]. To step out of a function or a method you can use [Shift + F11].

One further thing: To go to the next breakpoint you can use [F5] as well.

increase visual studio coding speed

This is a collection of how to increase your coding speed in visual studio. I will write this based on Visual Studio 2017:

Search:
You have the ability to search for everything you can imagine with [(ctrl + q)]. With the escape-key you can go one step back with the cursor into your code.

Bookmarks:
With bookmarks you can go to set a reminder to review this code-part later by pressing [(ctrl + k) + (ctrl + k)]. This works like a debugger-point. By pressing [(ctrl + w) + (ctrl + k)] you can see all bookmarks. With the menu-key (right next to the right windows-key) you can rename or delete a bookmark. With just hitting enter you can go and visit a place that you marked with a bookmark.

Code snippets:
As well there are a lot of code snippets that will increase your coding speed. Here are some examples:

  • ctor: constructor
  • prop: property
  • propfull: property with full get and set methods
  • wl: write line
  • equals: overriding object.Equals and object.GetHashCode function
  • try: try block
  • tryf: try block with a finally
  • for: a for loop
  • forr: a for loop which will decrease
  • ctor: constructor
  • foreach: foreach loop; if you created a list right before doing this it will auto-suggest the name of the list that you created
  • while: while-loop
  • do: do-while loop

Auto-Format:
To auto-format your code you can use the shortcut [(ctrl + k) + (ctrl + f)]. Another opportunity is to download the Microsoft “Productivity Power Tools“. After installing you have to go to Options -> Productivity Power Tools -> PowerCommands:General and make sure that “Format document on save” is set. Now you just have to save the file ad it will auto-format everything. As well it will remove all of the using-statements that are not used right now.

Switching Tabs:
As well you should use the keyboard to switch the tabs in Visual Studio. For this you can use the shortcut [(ctrl + tab)]. To go to the last tab you can go with [(ctrl + shitft + F6)]. To close a tab you can use [(ctrl + F4)].

Navigation
To navigate through your project I recommend you to use the shortcut [(ctrl + ;)]. This will open an dialog which will give you the opportunity to search for everything that you need. You can search for a class, a method, a file, …

Concentration to the right code
To bring you into the code you can switch between full-screen and the normal view with [(shift + alt + enter)]. To collapse code blocks you can use [(ctrl + m) + (ctrl + m)]. This works on every level (class, method, …).

Let Visual Studio work for you
In Visual Studio there is another godlike opportunity to avoid coding. If you have any part that is underlined you can go there and use [(alt + enter)] to have some options that will suggest you to finish your code correctly: