Thursday, August 6, 2009

Using BING Maps in your ASP.NET Applications

I was using the Google Maps API last week on a project and realised that the who JavaScript thing was a bit of a pain to debug.  Although it works fine, it’s fast and is easy to use it still gave me pause for thought.  so looking around for an alternative I decided to give the Microsoft offing a quick once around the block.

Installation

First off you’ll need Visual Studio 2008 to be installed and to down load the Windows Live Tools for Microsoft Visual Studio which contains all the DLLs you’ll need.  It also comes with other bit and pieces, but this post only relates to the mapping element.

After saving the file to your local drive execute the WindowsLiveTools.msi.

image

Click next and follow all the onscreen prompts.

Adding a Map to your site

Microsoft have made it very easy to adding a map to your website, once the software has been installed you get a set of new tools in Visual Studio.

Open up any ASPX Page in design view and select the “Map” icon within the Virtual Earth group on your tool bar:

image

Drag this icon to your' page.

image

Next you need to select a ScriptManager from within the “Ajax Extensions” group and drag this to your page too.

Press Play to debug your application and make sure it’s working.

image

By default you open up over the North American continent which is not the best for an Irish company.  So to fix this we have to go into the page code behind.  Open up the default.aspx.cs file and add the following code:

protected void Page_Load(object sender, EventArgs e)
{
    Map1.Center.Latitude = 53.33306;
    Map1.Center.Longitude= -6.24889;
}

Press Play again and you should see the following:

image

Doing Directions

One of the key advantages to mapping is the ability to get directions from one place to another.  Microsoft have made this really, really easy by just creating a generic list of string with valid addresses.

Create two text boxes on the page with a submit button.

 image

In the code behind add the following to the on click event for the button.

using Microsoft.Live.ServerControls.VE;

protected void btnRoute_Click(object sender, EventArgs e)
    {
        RouteOptions options = new RouteOptions();
        options.SetBestMapView = true;  // will zoom into the route
        List<string> address = new List<string>();
        address.Add(tbxFrom.Text);
        address.Add(tbxTo.Text);
        Map1.GetDirections(address, options);
    }
}

Press play on the application; type the following into the fields and press the “Route” button:

From: East Point Business Park, Dublin, Ireland
To:     O’Connoll Street, Dublin, Ireland

image

Here is the result….  simple and easy…

Tuesday, July 7, 2009

Generating SQL Diagrams using MS Visio 2003

You can build a set of database diagrams using Visio 2003 SP1.  It’s not the best solution but it does work to some extent.  Like all reverse engineering tools it assumes that you have implement some form of relationship mapping and constraints in within the database.

1) Open Visio and Select “Database/Database Model Diagram”

image

2) From the menu choose Database / Reverse Engineer

image

3) Set up your connection to the database

image

choose SQL Server / click New.

image

Select System Data Source and click Next.

image

Select SQL Server and click Next and Finish

image

Enter a meaningful name and enter the DB Server you want to work against (in this case Dubwsdev001), click Next and Next again to use Network Authentication.

image

Select your database and click Next and Finish and then OK.  Click Next at the Reverse Engineering Wizard dialogue.

image

Select the times you want to reverse engineer and click Next.

image

Select the Tables/Views you want to work with and click Finish.

image

You should now see the table in your Visio page. 

Remember that this reflects the table structure exactly, so if there are lots of columns, you’ll see lots of columns.  After a few hours playing around you’ll probably find doing it by hand is easier.

Alternative Solution

You can also use SQL 2005 or 2008 Management Studio to create database diagrams, however we don’t have a copy of that here.

Thursday, June 18, 2009

WCF on Multi Host Servers

I ran into this problem today when I was working on a WCF project.  A project which was working fine on my machine start producing the error “This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. Parameter name: item

image

Turns out that because the server was hosting a number of different sites using different Host Headers WCF needs to know which of the hosts to respond too.  You can do this by added the following to the services web.config file.

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
        <add prefix="http://www.blahblah.com"/>
    </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

        ……

   </system.serviceModel>

 

That tells the service to only respond on the specific header.

Wednesday, June 17, 2009

Self signing your server for SSL

I’ve been playing around with WCF and one of the problem areas is that our secure servers use a reverse-proxy configuration to route requests for web services.  This is all fine for old web services; however WCF is a little more particular with it’s requirements.  The reason for this is that the SSL Certificate does not actually exist on the Secure Server, it exists on the Proxy server, therefore when WCF starts it brings up the error saying “SSL is not supported”.  To resolve this we need to provide the server with a mock certificate using the same domain name as that used by the Proxy server.

To create a local mock SSL certificate for your development machine is quite easy and is also very useful to have if you are doing testing.

Installation

  1. Download the Internet Information Services (IIS) 6.0 Resource Kit Tools from the Microsoft site.
  2. Run the installation  image

         image

3.  Choose a complete install and follow all the instructions until it’s finished.

4.  Now you go to your Start/Programs/IIS Resources/SelfSSL/SelfSSL.

      image

5.   You need to work out your Site ID and the easiest way to get this is to use IIS Admin right click the website properties and go to Logging properties in the website Tab and look at the Log File name below the Site ID is “1”.

       image

6.   Enter the command “SELFSSL.EXE /S:1” and confirm “Y”.

      image

7.   Your site is now activated to use SSL.

     image

Monday, June 8, 2009

SharePoint Site Templates

I was recently asked to change the basic template used when creating a site for the first time from a Blank Site to Team Site.  As the site was created using a PowerShell script it required finding out which code should be used for the sitetemplate option in the STSADM command.

# Create new WebSite
stsadm.exe -o createsite -url $spwebsite -title "My Team Site" -ownerlogin entirl\$username -owneremail sharepointadmin@enterprise-ireland.com -sitetemplate STS#1

Friendly Name Template
Team Site STS#0
Blank Site STS#1
Document Workspace STS#2
Wiki Site WIKI#0
Blog BLOG#0
Basic Meeting Workspace MPS#0
Blank Meeting Workspace MPS#1
Decision Meeting Workspace MPS#2
Social Meeting Workspace MPS#3
Multipage Meeting Workspace MPS#4
Document Center BDR#0
Records Center OFFILE#1
Personalization Site SPSMSITE#0
Site Directory SPSITES#0
Report Center SPREPORTCENTER#0
Search Center with Tabs SRCHCEN#0
Search Center SRCHCENTERLITE#0
Publishing Site CMSPUBLISHING#0
Publishing Site with Workflow BLANKINTERNET#2
News Site SPSNHOME#0

Saturday, June 6, 2009

Set of very interesting Webcasts

I was doing some surfing over the weekend and came across an very interesting site called Dime Casts.  It’s a selection of tutorials that don’t take longer than 10 minutes.

Some of the topics covered are very interesting in terms of good .Net programming techniques for using Design Patterns.  Check it out if you have a few minutes.

Tuesday, June 2, 2009

Set of very interesting Webcasts

I was doing some surfing over the weekend and came across an very interesting site called Dime Casts.  It’s a selection of tutorials that don’t take longer than 10 minutes.

Some of the topics covered are very interesting in terms of good .Net programming techniques for using Design Patterns.  Check it out if you have a few minutes.