Hosting WCF in SharePoint 2007

If your MOSS site has controls or webparts based on Silverlight, you may need a WCF service for server side operations. Hosting this WCF service in Sharepoint web application is obvious choice for most of developers, however, SharePoint 2007 does not allow WCF to be hosted inside a web application.  Therefore we need to create a custom VirtualPathProvider and install that using HttpModule.

The Steps are:

1) Create a directory in the WSS site virtual directory so that relevant security permissions are simply inherited. Run the following – “%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe” -r –y .This Re-registers the current version of WCF and updates scriptmaps at the IIS metabase root

2) Create a WCF library and install it in GAC.

3) Create the relevant .svc file in the directory created above.put all thwe configurations in the a web.config specific to this folder.

4) Create a Virtual Path Provider and register it using a http Module.

SPVirtualPathProvider isn’t coded to handle URLs that start with ‘~’. So we need to have our own as:

 

public class WCFVirtualPathProvider : VirtualPathProvider
{
  public override string CombineVirtualPaths(string basePath, string relativePath)
  {
    return Previous.CombineVirtualPaths(basePath, relativePath);
  }

  // all other methods omited, they simply call Previous… like the above.
  public override bool FileExists(string virtualPath)
  {
    string fixedVirtualPath = virtualPath;
    if (    virtualPath.StartsWith(“~”) && virtualPath.EndsWith(“.svc”)   )
   {
      fixedVirtualPath = virtualPath.Remove(0, 1);
    }
    return Previous.FileExists(fixedVirtualPath);
  }
  protected override void Initialize()
  {
    base.Initialize();
  }
}

5) Register the provider using a custom httpModule as:

Our HttpModule will run after Sharepoint’s “SPRequest” module. Since SPVirtualProvider is registered by the “SPRequest” module at startup, we know our VirtualPathProvider will always come into play *after* Sharepoint’s SPVirtualPathProvider and therefore, we will get a chance to patch the request’s virtual path before it reaches Sharepoint.

public class WCFVPPRegModule: IHttpModule
  {
  static bool wcfProviderInitialized = false;
  static object locker = new object();
  public void Init(HttpApplication context)
    {
      if (!wcfProviderInitialized)
      {
        lock (locker)
      {
      if (!wcfProviderInitialized)
      {
        WCFVirtualPathProvider wcfVPP = new WCFVirtualPathProvider();
        HostingEnvironment.RegisterVirtualPathProvider(wcfVPP);
        wcfProviderInitialized = true;
      }
    }
   }
  }
#region IHttpModule Members
  public void Dispose()
  {
  }
#endregion
}

Homeschooling Through Technology

The educational process can be tough on kids and parents alike. It can be difficult to prevent it from becoming mundane. That’s why I think apt use of technology is so important—it allows both the student and the educator to remain excited with their educational journey.

Having done homeschooling for a while a bit now, I can definitely say that my child is given the opportunity to choose what they want to learn and that we have a wealth of resources to draw from beyond the traditional classroom.   What to learn biology and butterflies?  Order a kit to raise your own butterflies, watch them grow and learn about what a chrysalis is and what metamorphosis is.

image

Google Maps is a great tool to use if you’ve reached a point in your learning path dealing with either geography or history. At this point, I think we’ve all messed around with the satellite or Street View feature in Google Maps (how many images of people “caught out” have we seen Google capture?). However, thanks to tools built into the service, it can also be a rather useful educational resource.

History and dates are tough for young children to grasp, but let’s say your currently teaching a unit on the Civil War. Rather than simply looking at static maps, plot out Grant’s march to the South or Lee’s penetration into Union territory. By actually engaging in the geographical reality of history, it becomes much more real.

Wikipedia is another great resource on just about anything. You’ll often hear people claim that it’s either unreliable or inaccurate. While it’s true that literally anyone can edit or add information to Wikipedia, take a look at this interesting statistic from a CNET article from back in 2005, before it really even took off.  And of course, research may start at Wikipedia but it doesn’t end there, it is a jumping off point to more interesting avenues of deeper understanding that your child will love to explore.

The best thing about home schooling?  Each day can be tailored to your child’s interests.  It turns the learning process on its head.  It is not, “Here’s what you must learn today”, instead it is “What would you like to learn today?”  Children are active and engaged in the learning process.  How many times can children put the words “fun” and “education” in the same sentence when they are in a room full of 40 other children?

Does Recycling Work?

Interesting article.  People are lazy, make it easy for them or they’re not going to do it.  And let’s face it, a little recycling is better than none, right?  Single stream may degrade the materials and amount, but isn’t that offset by the fact that more people will do it?

These days, some cities are making recycling as mindless as possible by implementing "single stream" recycling, in which paper, metal, plastic, and glass are all mixed together in one bin. Should this be our standard nationwide? Proponents argue that it makes people more likely to recycle; others counter that the quality suffers. Miller is all for simplicity, but says single stream "degrades the material and reduces the amount that can be made into new products."

http://www.motherjones.com/environment/2009/05/recycling-fuhgeddaboudit

Compost – Carbon-to-Nitrogen Ratios

A couple of months ago I posted about Compost-What’s In and What’s Out.

However, it’s not enough that you throw your organics, food and yard waste into your compost bin (although it’s a good start!)  You must also be aware of the carbon to nitrogen ratio so as to keep your compost happy, healthy, and not stinky!  For best performance, the compost pile, or more to the point the composting microorganisms, require the correct proportion of carbon for energy and nitrogen for protein production. Scientists (yes, there are compost scientists) have determined that the fastest way to produce fertile, sweet-smelling compost is to maintain a C:N ratio somewhere around 25 to 30 parts carbon to 1 part nitrogen, or 25-30:1. If the C:N ratio is too high (excess carbon), decomposition slows down. If the C:N ratio is too low (excess nitrogen) you will end up with a stinky pile.

Below are the average C:N ratios for some common organic materials found in the compost bin. For our purposes, the materials containing high amounts of carbon are considered "browns," and materials containing high amounts of nitrogen are considered "greens."

Estimated Carbon-to-Nitrogen Ratios
Browns = High Carbon C:N
Ashes, wood 25:1
Cardboard, shredded 350:1
Corn stalks 75:1
Fruit waste 35:1
Leaves 60:1
Newspaper, shredded 175:1
Peanut shells 35:1
Pine needles 80:1
Sawdust 325:1
Straw 75:1
Wood chips 400:1
Greens = High Nitrogen C:N
Alfalfa 12:1
Clover 23:1
Coffee grounds 20:1
Food waste 20:1
Garden waste 30:1
Grass clippings 20:1
Hay 25:1
Manures 15:1
Seaweed 19:1
Vegetable scraps 25:1
Weeds 30:1

Note: Many ingredients used for composting do not have the ideal ratio of 25-30:1. As a result, most must be mixed to create "the perfect compost recipe." High C:N ratios may be lowered by adding grass clippings or manures. Low C:N ratios may be raised by adding paper, dry leaves or wood chips.  Many home gardeners will put up with a slight odor and keep some excess nitrogen in the pile, just to make sure there is always enough around to keep the pile "cooking!" Learn more about building a hot compost pile here.