WCF with no service xml or endpoints? What is this magic?

I had to write a WCF service for a project and I hadn’t created a WCF service for a while.

I was trying to write mine to fit in with the rest of the projects but I was totally confused because I was looking at the other WCF services in the project and looking to copy the shell and modify (like all good developers do:-))

I could see there was a SVC file, I could see the code but in the web.config there was no service xml section for the WCF service.

I trying to look at the url for the SVC to see if I could see the wsdl but when I did I got the message no endpoint found.

no endpoint found

 

WHAT WAS GOING ON.

Sometimes as a developer, when you haven’t worked on an area for a while, you have a horrible feeling they have changed the way it worked to some completely new method and framework a bit like the way web services were replaced with WCF.   but this wasn’t the case, it was CRM 2011 project (not that makes any difference calling a WCF service).

The most puzzling aspect was the WCF code was being called (I called it myself to make sure it worked) from a Javascript form.

I asked a developer and he said it must be a factory service, I must have had a completely blank look on my face because he then offered to show me.  A good tip is if you don’t understand something ask someone to point you in the right direction because you can save yourself days of puzzling.

He said right click on the SVC file in Visual Studio and choose View Markup
 
You will see this
mine was like this
<%@ ServiceHost Language=”C#” Debug =”true” Service=”Hosk.HoskRibbonService” CodeBehind=”HoskRibbonService.svc.cs %>
he said change it to this
<%@ ServiceHost Language=”C#” Debug =”true” Service=”Hosk.HoskRibbonService”  Factory=”System.ServiceModel.Activation.WebServiceHostFactory” %>

I removed the service xml section in the web.config and then as if by magic it worked and I was able to call the wcf service using jsonp call (cross domain) in javascript.

Not only had I never heard of using WebServiceHostFactory to create a WCF but I had never come across it in any of the code I have worked with.

I was interested to learn a bit more about it,  It’s a way to dynamically create services and it automatically creates the endpoints for the service and was added in .NET 3.5

 

Here is MSDN class

http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.webservicehostfactory(v=vs.110).aspx

 

this flashcard gives a good quick explanation

http://www.brainthud.com/cards/5218/25206/what-is-the-purpose-of-the-webservicehostfactory-class-and-how-is-it-used

Question

What is the purpose of the WebServiceHostFactory class and how is it used?
Answer

When hosting a web service in IIS, the WebServiceHostFactory class can be used to automatically configure the endpoints for the service. Endpoints will be configured to use WebHttpBinding and WebHttpBehavior. The WebServiceHostFactory class will automatically create a WebServiceHost class when the web service is activated. The following example demonstrates how to reference the WebServiceHostFactory in a .svc file:

<%@ ServiceHost 
    Service="OrderService" 
    Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

 

 

Here are some simple tutorials if you want to learn more

http://dotnet.dzone.com/articles/creating-restful-wcf-service

http://agilewarrior.wordpress.com/2010/12/19/how-to-create-a-simple-wcf-rest-service/

http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/rest-eanbaled-service-in-wcf-tutorial/

 

Picture from http://daarken.com/blog/2012/08/11/lotr-magic-and-other-news/

Advertisements

PASSED – 70515 – .NET Framework 4, Web Applications certification

Yes I have finally done it.

After studying (on and off) for 6 months I finally passed the .NET Framework 4, Web Applications certification.  It was a major undertaking to pass this exam and it involved reading the excellent but very very long book

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Developement with Microsoft .NET Framework 4 book

which was around 900 pages of reading and doing all the examples.  I also watched numerous video nuggets and learn asp.net videos.

Then I did lots and lots of practise exams but it was finally all worth it.

I passed a Java 5 certication a number of years ago and I would say this was a similar in the amount of effort.

I think the certification is very pretty useful for people who would want to develop web applications or learn more about how they work, it covers lots of things you will find useful like PAGE lifecycles, debugging, data linking, web controls, master pages, MVC 2 and lots of other things.

If you are a CRM developer this will probably go into more detail than you will find useful (unless you are going to be linking websites with CRM).  It did have a few new features used in CRM 2011, like LINQ etc so I am glad I have done it.

I got 850 out of a 1000 and took the test at 8.30 am.

I’m glad I have finally got it out of the way because it was starting to loom over me a bit.

The good news is I can start to have a look at the Sure Step certification which is a lot smaller exam and will include something I can use in my CRM work.

70-515 – Introduction to MVC 2 Videos

I have been studying the 70-515 .NET 4 Web Certification since the start of the year.  I am using a few different sources of information but the main one is the MCTS Self-Paced Training Kit (Exam 70-515): WEb Applications Development with Microsoft .NET Framework 4 book.  Yes I agree it’s a catchy title which they must have spent  a long time deciding on, well along time saying it that’s for sure.

This book is excellent, it describes things in an easy to understand way, the only complaint I have is it’s massive, I have worked out it’s 880 pages and today I have gone past the half way stage, yes I have read 441 pages.  If you would like to buy the book, get over to Amazon here

I am also watching some videos and today I watched a video on MVC 2, which features loads on the practise exam questions I have been testing myself with.  Before I watched the video I was terrible at the MVC 2 questions but I had to wait until round to learning it because there are loads of things to learn for the 70-515 exam.

I have to say my first impression of MVC 2 is it’s confusing and it seems like you have to put loads of configuration values in classes and within error prone “TEXT” strings.

I don’t think I fully understand it yet but my first look is it reminds me a bit of the Java framework Struts and Spring which used to filter messages to and from the backend to the frontend.  The beauty of Struts and Spring was you put all your mapping into xml files which seems easier to deal with because all the vales were in the same place.  You also had to create folders in correct locations, whilst I was watching the videos I thought it must be very difficult to bug fix an MVC 2 solution if you had done something wrong in the setup.

I can imagine that it would be quite complex if you had loads controllers and views

The first thing I have noticed is that I have started to understand the questions on my practise test.  I also noticed in a few places there is MVC 3, bloody hell I haven’t learnt MVC 2 yet.

So I thought I would give myself some homework to learn more about MVC 2 before I read the chapter on it and here are some links
http://channel9.msdn.com/blogs/matthijs/aspnet-mvc-2-basics-introduction-by-scott-hanselman

http://www.asp.net/mvc/videos/how-to-best-learn-asp-net-mvc

http://www.asp.net/mvc/videos/understanding-models-views-and-controllers

http://bradwilson.typepad.com/blog/2010/04/advanced-aspnet-mvc-2.html

 

Visual Studio 2010 and .NET Framework 4 Training Kit

For people studying for the 70-515 – Web Applications .NET 4 exam.   You will need to know a Ajax, MVC 2, ASP.NET controls.

Microsoft have rather nicely created some training courses, which you can find here

The training course focuses on Visual Studio 2010 and .NET 4.  This is a lot of the areas covered in the exam.

here are the units covered in the course

Units

OverviewIn this introductory unit, the Visual Studio 2010 and .NET Framework 4 evangelism team welcomes you to the training course and goes over the significant changes to Visual Studio 2010 and the .NET Framework 4. We’ll also cover what you’ll see in the course and how to follow along with the labs.

 

Managed LanguagesThere are same great enhancements to the set of managed languages in Visual Studio 2010. Not only do C# and Visual Basic continue to evolve together as premier languages in Visual Studio, but we also added a new functional programming language called F#.

 

ASP.NET 4In this unit, we’ll cover the enhancements to ASP.NET in the .NET Framework 4. You’ll learn about changes to WebForms, AJAX and Dynamic Data and you’ll get introduced to ASP.NET MVC, now included in the framework.

 

Data PlatformAlmost every application needs to interact with data. In this unit, you’ll learn about the enhancements to the .NET Framework’s data access technologies including ADO.NET Data Service, ADO.NET Entity Framework and Microsoft Distributed Cache.

 

Windows Communication Foundation and WorkflowWindows Communication Foundation and Workflow are significantly improved in the .NET Framework 4. In this unit, you’ll learn about the improvements to both as well as the integration of the two which make it easy to expose Workflows as services.

 

Parallel ComputingParallel computing is an important focus in the .NET Framework 4 as developers create applications that can take full advantage of multi-core processors. In this unit, you’ll learn about the new additions to the .NET Framework to make developing parallel code easier.

 

Application Lifecycle ManagementVisual Studio 2010 includes a first-class set of Application Lifecycle Management tools. In this unit, we’llcover several of the new ALM features in Visual Studio 2010

 

CRM 2011 – LINQ Videos

I have been using LINQ in CRM 2011 recently and I am loving it and I also need to study LINQ for the .NET 4 exam.  So I was looking for some videos about LINQ so I could understand using in CRM but also some more general videos.

this first video is great for CRM 2011.  It’s done by David Yack and is included on the official CRM 2011 Development kit.  It goes through some general examples CRM 2011 and LINQ.

LINQ Provider

 

The two videos below are general LINQ videos and just show examples of LINQ.  I found these useful for the 70-515 Web applications exam.

LINQ to SQL Overview

 

LINQ Tutorial Video

 

 

ASP.NET Page Life Cycle

studying for the 70-515 .NET 4 web exam I need to know about the ASP.NET page life cycle.

Event Life Cylcle of an ASP.Net Page.

Life cycle stages:-

  1. Page request
  2. Start
  3. Page initialization
  4. Load
  5. Validation
  6. Postback event handling
  7. Rendering
  8. Onload

Life Cycle Events:-

  • PreInit
  • Init
  • InitComplete
  • PreLoad
  • Load
  • Control events
  • LoadComplete
  • PreRender
  • SaveStateComplete
  • Render
  • Unload

 

I have also found a couple of useful videos, I like to reinforce information I have read by watching videos because the person in the video often explains in a more descriptive and memorable way than just reading the information.

This video is from Microsofts ASP.NET

Page Lifecycle Events

This video is a decent explaination of the page lifecycle

http://www.youtube.com/watch?v=sOVBrLvhOHU

The plan to pass the Web Applications Development with Microsoft .NET 4. certification

I was working through a chapter for my Web Applications Development with Microsoft .NET 4.  I was just finishing the second chapter and the whole self study book has 14 chapters.

I was thinking how much progress should I be making.  I had set myself an a target of doing most of the studying by the end of March.

I had also been doing practise exams, watching videos, reading around the subject.  But my main target is working through this book, so I thought to myself I need to know how many pages I need to read each week so I am on target to get this done by the end of March.  This is mentioned in the post – https://crmbusiness.wordpress.com/2011/01/31/seven-steps-to-certification-success/

The important factor here is the importance of setting a goal/deadline.  Once you have done that then you know the amount of work you need to do each week to achieve you goal.

So with the book I’m reading, it’s 880 pages, so I roughly need to read around 100 pages a week.

I noted down all the chapters in an Excel spreadsheet so I can track my progress.  Now that is sad.

70-515 – Self paced chap pages chap start chap end percent current page current percent
Chap 1 39 1 40 4.55
Chap 2 55 41 96 10.91 96 10.91
Chap 3 63 97 160 18.18
Chap 4 66 161 227 25.8
Chap 5 63 228 291 33.07
Chap 6 37 292 329 37.39
Chap 7 57 330 387 43.98
Chap 8 65 388 453 51.48
Chap 9 97 454 551 62.61
Chap 10 71 552 623 70.8
Chap 11 61 624 685 77.84
Chap 12 101 686 787 89.43
Chap 13 43 788 831 94.43
Chap 14 48 832 880 100