WCF Tutorial: now on YouTube

Advertisements

AngularJs: their own tutorial

I’m often looking for the “right book”, the “right PluralSight course” when searching for education. But I often forget that, done well, online tutorials and documentation can be very good. And so it is with Angular’s tutorial. By lesson 2, they are onto testing, after good examples of app directives and controllers.

The tutorial is here.

Recording sound from your sound card

On another PC, the SoundMix option in Windows sound options was a reasonable way of recording soundcard (Realtek) output to a wav file. However, that option is not there on my current laptop, which has an NVidia soundcard. Sure I could code something myself… but it looked like the effort was greater than the reward. In the end, I used the combination of 2 pieces of paid-for software, to get a working audio file that I can put on SoundCloud to demo my musical intervals app. Those 2 software packages are:

Soundcast-o-matic, which despite the cheesy name, works great for screen recording, and has a very reasonable subscription model. This allows me to save to .avi, which is recognised by..

Sony Sound Forge Audio Studio 10.0, which though old, works fine on Windows 10… as long as you haven’t lost that precious license key. I can extract the sound from the .avi, and save it as .mp3

In ITunes, I can then add the file, attach to a playlist, specifically for the purpose of burning that to a CD.

SoundForge02

 

.Net: Hosting a simple WCF service in IIS

This assumes you have read the previous post, which left us with a simple service. However, it was only hosted/running while we were running in debug mode in Visual Studio. We don’t want to be, and can’t be dependent on a running VS instance. This looks at how to take that service and host it in IIS. It does not involve using Visual Studio.


 

This is the folder that contains our code and binaries for the service:

WCFinIIS01

Turning to IIS, this is how it looks before I change things:

WCFinIIS02.JPG

Add an application…

WCFinIIS03

Actually, I shall interrupt this to bring the service files under the inetpub/wwwroot folders – most of them anyway, and then whittle away at them to confirm the minimum set I need:

WCFinIIS04

In fact, I’m fairly confident about that minimum set, so I’ll just go ahead and cull them giving this (note that I have renamed app.config to web.config):

WCFinIIS05

… and the dll.config may go as well, don’t know yet:

WCFinIIS06

Now we go back to IIS and add all that as a new application to the Manager:

WCFinIIS07

OK, and now we have this:

WCFinIIS08

Now, just naively browsing to the root URL for that will get us nowhere:

WCFinIIS09

Reminding ourselves of the content of that root folder shows only 2 files, both of which are important… and wrong right now:

WCFinIIS05

web.config: both the highlighted entries should be removed (but keep a copy of the HelloAcmeService/HelloService entry for the svc file in the clipboard). You will/may need to be in admin mode to edit web.config under the IIS nodes:

WCFinIIS10

AcmeService.svc:

This is wrong in that the Service tag is pointing at the interface, and should be referencing the implementation, that is, IHelloService needs to change to HelloService:

WCFinIIS11.JPG

After those change, this is now what we see if we Browse Website in IIS:

WCFinIIS12

This location will never have a default or any readable web page – it is all about delivering a Service. If we now put an appropriate entry in the URL, we see…

Hm, interesting… this is symptomatic of specifying the interface, not the implementation:

WCFinIIS13

And wadya know, I hadn’t actually saved the change (or maybe the admin rights prevented it) after taking the screenshot. So making sure I press Save after this edit (in fact I found I needed to stop the web site in IIS first):

WCFinIIS14

Now we go again to the URL:

WCFinIIS15

That is good, if it is not obvious. That’s enough for this post, I think. The next post will talk about the wsdl, and using that in SoapUI to test the service from that angle.

 

 

.Net: simplest WCF service and client

In VS2015, I wanted to create the very simplest possible WCF service, and a client, in the form of a console app, to prove it works.

In VS, use the WCF template to create a WCF service library. As the template is a Hello World, I choose to call it HelloAcmeService (I don’t know why I’m randomly picking fictitious brands):

That creates an interface file, and a class file, which contain more than I want, so we strip those back to a minimum, and do some renaming.

Before:

HelloAcmeService02


HelloAcmeService03


HelloAcmeService04


HelloAcmeService05


 

After…

…removing the stuff I don’t want, and some renaming:

HelloAcmeService06


 

HelloAcmeService07


HelloAcmeService08


HelloAcmeService10

After an OK build let’s make sure we can reference it from the browser, by pressing Start in VS , and then clicking on the BaseAddress hyperlink  in the app.config (or just typing it in):

HelloAcmeService11

Now we could plug the WSDL into SoapUI and get a richer client experience (if those words mean nothing, that can be for another tutorial). For now, we’ll just create a console app to use the service.

Stop the service running in VS, so you can go back to editing. Create a console app under the solution (please note – there is in fact a compile error later using this name for reasons I am not going into here, and I won’t redo the screenshots – please call the console app HelloServiceAClient – note the ‘A’):

HelloAcmeService12

That gives you this new content in the Solution Explorer:

HelloAcmeService13

You now need to add a Service Reference to use the service from this client. Right click on References/Add Service Reference…, and in the dialogue, click Discover:

HelloAcmeService14

Click OK, and Solution Explorer now looks like this:

HelloAcmeService15

Now in Program.cs, add the text highlighted to access the service and use the GetData() method from the service:

HelloAcmeService16

The last action before testing it is to right-click on HelloServiceAClient and select Set as Startup Project.

HelloAcmeService17

Now press the Play button in VS, and you get this exciting output:

HelloAcmeService19

That’s it.

 


DNX: a console app on a Windows client with no pre-existing dev tools

Summary: Previously, I got a trivial console app working using DNX. However, As Visual Studio 2015 was on that box, I could not be sure how much help that was giving me under the covers (especially as I started it using a VS template). This post just confirms that you can run a console app on a bare Windows 10 box, with no development environment or tools present, once you have made the necessary trip to GitHub.


Proving out dnx and its mates is getting to be a bit of a drug. I just know that even though I have absolutely zero justification for trying out it out on a Linux distribution… it will happen. 🙂

But back to the job in hand…

Using my Azure subscription, I spun up a Windows 10 Enterprise VM – out of the box, this has no developer environment or tools. I installed Google on that box (I have no idea why it assumes I’m in the Netherlands), and searched for [dnvm github] (or just go straight here):

DnvmGithub01

I picked a link, and downloaded the zip (note you do not have to log in just to get the zip):

DnvmGithub01

As I’m just playing, I saved that to the (temp) d: drive on the VM, and expanded it:

DnvmGithub02 DnvmGithub03

I decided that the I would just have a go with the dnvm.cmd:

DnvmGithub04 DnvmGithub05

PowerShell (called from the .cmd) knows that the .ps1 came from the Internet, so let that through:

DnvmGithub06 DnvmGithub07

Let it install the DNX runtime for me:

DnvmGithub08

This has also updated the path for me, to find dnx

DnvmGithub09

DnvmGithub10

But DNVM isn’t on the path. OK, I could put that there by hand, but for now, I’ll just navigate to its location. Note that it was evidently a mistake to earlier save it to a temporary location – I will need it another time:

DnvmGithub11

As said, this is a new Windows box, so update the execution policy:

DnvmGithub12 DnvmGithub13 DnvmGithub14

In fact, running dvnm upgrade is evidently redundant, well, this time anyway, as it is doubtless repeating stuff done in the dnx wizard earlier:

DnvmGithub15

So now I have copied across the 3 files from yesterday, ie the .cs, the .xproj, and the project.json. This confirms that neither a .sln nor a .csproj are needed. However, I am not yet clear on the implications for msbuild. I don’t care about that right now:

DnvmGithub16

With those minimum files in place, I can now run [dnu restore] to read the project.json file and download the dependencies. There are some errors… but I’m not going to examine those right now:

DnvmGithub17 DnvmGithub18

With all dependencies hopefully resolved, we can execute the Program.cs, using

[dnx -p .\project.json run]

… and that gives me the hoped-for result:

DnvmGithub19

Note that although I used the console app from yesterday, the dnx download actually contains its own console app, so I could have used that. For this exercise, I would not have needed the .sln file, but for something more enterprisy, maybe I would need a .sln file:

DnvmGithub20


Next day…

I just spent not more than 5 minutes on my Linx Windows tablet going through all the above steps. As a plus, I was also able to load Visual Studio code, edit the .cs in there, get Intellisense working, AutoSave, and then re-run dnx against it. This time round I did use the sample console app rather than my own. The only interesting thing in that was that in VSC the OmniSharp/Roslyn parser saw that System.Diagnostics was not required, and offered to remove it. Great.

I think right now the one gap in my mind is seeing how the new (?) MsBuild fits in to this, when you have more complex dependencies. But that will do for now.