Nerdly Things

.tech and personal blog of david stanley.

p 1 | 8

LAST NEXT

I still live!

11/29/2012

So it has been leaving me with guilt that I have not updated the site with new work since its inception basically. Bad for my image I am sure, but the thing is, I have so much new work that I don't have a spare second to get them uploaded here! Hopefully by the end of the year, beginning of next year I will have some hours I can allocate to update the folio and let you all know what I have been up to!

Happy holidays and stuff

 

-D

Comment

I Signed up for Fixr!

9/20/2012

Just a test run so far, but it seems promising.

Check me out here:

 

Nerdly Things LLC

Comment

Moving the blog portion of this site to wordpress

9/7/2012

Don't judge me, its just easier to accomplishe things over in wordpress-land, and I want to focus on other things on this main site (mainly migrate it over to a more professional landing page for my freelance work. 

Head over to ninjamark.com to see the new blog. Both this site and that one will be going through some formatting and style changes over the next couple weeks, but the end product will be a much friendly web experience.

Cheers,

{David Stanley}

Comment

Klout update!

8/24/2012

So I have been experimenting with a couple of things the past couple of weeks. Klout and BrandYourself. Most already know what Klout is, and like many, I think it is stupid as well, BUT, I wanted to give it an honest chance to see if my initial opinions are correct or not. BrandYourself claims to help make sure your name has good stuff show up in search engines rather than the bad stuff. We'll get to that in another post probably.

I am about ten days into Klout and thus far find it fun to check it and see my score rise. I am a big fan of graphs and data visualization, so watching my little line go up is fun. But so far that is it, just a fun little 3 minute distraction. I have my google+, twitter, and linkedIn profile attached. I am really only active on g+ and linkedIn. Right now I am sitting at a solid 40, so cool? I don't have a facebook, nor do I want one again, so I don't know if that is going to punish my overall score. Another thing I wonder about is if there is a way to attach websites to your data. Not that this site will provide me much 'klout', but a lot of influential people, in my opinion, are mostly influential on there personal sites. Scott Hanselman comes to mind. 

I don't know, I am having fun with it, but I still find the data to be mostly useless. 

Am I doing it wrong? Is there features that I haven't discovered yet that could make this toy a tool? 

{David Stanley}

Comment

Introduction to Windows Communication Foundation - Simple Hosting of a WCF Service in a Console Application

8/14/2012

Short and simple here, I am going to show you how easy it is to host your Windows Communication Foundation web service in a console application. I am doing a console application so we can focus on the code involved, no so much an underlying project structure (we will get into that in some other posts). If you are following along from the last post, then you will want to open up the solution that we created in that one, because we are going to start from there. If you did not take a look at the last post, I would highly recommend it.

Ok and here we go. First right click your solution and add a new Console Application

NOTE: In the screen shots I named my project ServiceHost, which caused some issues down the road. I would just name it ConsoleHost to avoid any trouble.

New Project

Now select the Console Application:

Console Application Project Screen

Now we need to add two references to this new project: one the System.ServiceModel, and the other reference is to our WCF Library Project:

Add references

And once in there add the two references:

System SeviceModel Reference

The Code!

First thing to do is add the following code the the Main method.

static void Main(string[] args)
{
    ServiceHost host = new ServiceHost(typeof(MessageService));

    host.AddServiceEndpoint(typeof(IMessageService),
        new BasicHttpBinding(),
        "http://localhost:8080/messages/basic");

    host.AddServiceEndpoint(typeof(IMessageService),
        new WSHttpBinding(),
        "http://localhost:8080/messages/ws");

    host.AddServiceEndpoint(typeof(IMessageService),
        new NetTcpBinding(),
        "net.tcp://localhost:8081/messages");
}

Simple stuff happening here. We are using the ServiceHost Class to instantiate a new instant of our service we created. After that we are adding some endpoints by giving it the Service Contract reference, the protocol we will be using, and a url to map it to.

No we can add a try/catch statement to test this out. The following code simply opens up the connection, keeps it open under the user presses a key, then gracefully closes.

try
{
    host.Open();
    Console.ReadLine();
    host.Close();
}
catch (Exception e)
{
    Console.WriteLine(e);
    host.Abort();
}

If you hit ctrl+F5 you should see the console window come up and just stay nice and empty until you press a key, and which point it will close. That is kinda lame, I am sure we would all like to see something indicating that things are as they should be. Now we will add a method that will print out some info the the console so we get the satisfaction we desire.

static void PrintServiceInfo(ServiceHost host)
{
    Console.WriteLine("The following service is running: {0}", host.Description.ServiceType);
    Console.WriteLine("The following endpoints are configured for this service:");
    foreach (ServiceEndpoint point in host.Description.Endpoints)
    {
        Console.WriteLine(point.Address);
    }
}

Now in your try statement in the Main Method add a call to PrintServiceInfo and pass it the host you created.

(so type PrintServiceInfo(host); for those who like to just see what to copy and paste)

Run that application again and you should see something like this:

Console Results

So you may be thinking, "Wow that is the coolest thing I have ever seen!!", or you are likely thinking, "Ok what was the point of all this?".

This may not seem very useful, and perhaps it really isn't, but now we can all see how simple it is the actually host a WCF service. This is all the code it took:

namespace ConsoleHost
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(MessageService));

            host.AddServiceEndpoint(typeof(IMessageService),
                new BasicHttpBinding(),
                "http://localhost:8080/messages/basic");

            host.AddServiceEndpoint(typeof(IMessageService),
                new WSHttpBinding(),
                "http://localhost:8080/messages/ws");

            host.AddServiceEndpoint(typeof(IMessageService),
                new NetTcpBinding(),
                "net.tcp://localhost:8081/messages");

            try
            {
                host.Open();
                PrintServiceInfo(host);
                Console.ReadLine();
                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                host.Abort();
            }
        }

        static void PrintServiceInfo(ServiceHost host)
        {
            Console.WriteLine("The following service is running: {0}"
                , host.Description.ServiceType);
            Console.WriteLine("The following endpoints are configured for this service:");
            foreach (ServiceEndpoint point in host.Description.Endpoints)
            {
                Console.WriteLine(point.Address);
            }
        }
    }
}

Not sure I can complain about it being too-complex and unsightly now. Damn.

Check back in the next few days and I will get into some more robust examples and experiment with the best way to host these things in an MVC app.

Regards

{David Stanley}

Comment

p 1 | 8

LAST NEXT
Post Archives