Tuesday, March 24, 2009

Rendering problems with IE8

Microsoft released IE8 during Mix 2009.  Microsoft spent a lot of time making IE8 comply with the browser standards.  When you upgrade your browser to IE8 if you find the web site does not render right.  Do not worry there is a simple fix for this. 

There is a tag you can place in the Head section of your webpage which will force IE8 into IE7 compatibility mode.

?
<html>
<head>
  <!-- Mimic Internet Explorer 7 -->
  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  <title>My Web Page</title>
</head>



For more info on IE8 compatibility read this article


Hope this helps

Saturday, February 21, 2009

Silverlight 2 GDR Available

This week Microsoft Release an GDR to silverlight 2 which included some minor fixes.

Here is a list of the main changes in the GDR (build 2.0.40115.0):
  • Fixes problems that were caused by Silverlight and McAfee scanning tools interactions
  • UI automation stability fixes, including:
    • graceful failures when attempting to use features that require .NET Framework 3.0 or 3.5 on machines that do not have either framework installed
    • improved Tablet support
  • Fixes an issue that arises when Mac users customize their environment by removing Arial and Verdana fonts
  • Fixes a known issue with Isolated Storage IncreaseQuotaTo method (see this post for more information)

The one fix which bothered me a lot is the graceful failures when attempting to use features that require .Net framework 3.0 or 3.5 on machines that do that nave either framework installed. Silverlight 2 has its own version of the .net framework why should it use .net 3.0 or 3.5 and of course the .net framework is not available for the mac.  Well after looking around some I found this in the comments on Tim Sneath's Blog
  " apologies - we could probably be clearer here on what this means. Essentially, this was a bug that could be triggered in certain situations where you were using the accessibility tools (e.g. magnifier) on Silverlight content on a machine without .NET Framework installed. In short, the bug was an accidental dependency that has now been removed." - Tim Sneath
For More info on the Update please check out Tim Heuer's Blog entry

Tuesday, January 13, 2009

Making a REST service with VB and WCF

REST which stands for Representational State Transfer is a way of sending data over the Internet without an additional message layer.  Standard web services use soap for there message header.  In this example we will create a service that uses the northwind database to send a  list of the products for a category.

Lets start by create a new VB web application. In that web application add a Ado.Net Entities data model.  In that class add the northwind database's product class.


Now add a service named Service1 to the web application.  Lets start by modify the web.config for the service to support rest.  First remove the ServiceBehavior section and add a endpointBehaviors section for webHttp.  In the endpoint we have to change the binding to webHttpBinding and the behaviorConfiguration to the webBehavior we created.

?
<system.serviceModel>
    <behaviors>
  <endpointBehaviors>
    <behavior name="webBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="True"></serviceHostingEnvironment>
    <services>
        <service name="RestTest.Service1">
            <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="" contract="RestTest.IService1">
            </endpoint>
        </service>
    </services>
</system.serviceModel>

When we added the service we got 2 items the wcf service and an interface for the service.  Before we go any further we need to add a reference to system.servicebehavior.web  

In the Interface we need to define the how the categoryId is passed to the service.  In this example it expects product/categoryID in the url for the service

?
Imports System.ServiceModel
Imports System.ServiceModel.Web
 
<ServiceContract()> _
Public Interface IService1
 
    <OperationContract()> _
    <WebGet(UriTemplate:="Product/{categoryID}", ResponseFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Bare)> _
    Function GetProducts(ByVal categoryId As String) As List(Of Products)
 
End Interface

In the service we need to set the AspNetCompatibilityMode and write some code to return the products

?
Imports System.ServiceModel.Activation
 
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class Service1
    Implements IService1
 
    Public Function GetProducts(ByVal categoryId As String) As System.Collections.Generic.List(Of Products) Implements IService1.GetProducts
        Dim dc As New NorthwindEntities
        Dim q = From p In dc.Products Select p Where p.CategoryID = CInt(categoryId)
        Return q.ToList
    End Function
End Class

To call the service you would use a url like http://localhost:2050/Service1.svc/Product/7


you will get an xml file like this returned