Technical Timeout 1

by Donn Felker 24. November 2008 16:02

I'm going to try a new thing out on my blog. It's called the "Technical Timeout" ... its a small time to take a break from Technology and get a laugh or two.

With that said, here is Technical Timeout, Part 1.

Introducing.... Terry Tate - Office Linebacker:

I advise that you use headphones on this. PG-13 language.

To a lot of you, this is old stuff, but to those of you who have never seen Terry Tate, oh goodness, you're in for a surprise. If you've already seen this... watch it again, its worth it.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Technical Timeout

Store Locator - Moved to Codeplex

by Donn Felker 23. November 2008 07:29

image

The Store Locator I built for ASP.NET has been getting a lot of traffic over the last year and requests have been coming in for new features like crazy. To manage this project a little more effectively, I've decided to move the project to CodePlex.

 

You can now download the source from Codeplex here (codeplex.com/storelocator).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | ASP.NET | GIS

Debugging Silverlight Tip

by Donn Felker 21. November 2008 03:09

If you're doing any kind of Silverlight work you're bound to get "Error on page" in Internet Explorer. Here's what I'm talking about.

You fire up your app in the browser window and BLAM. Screen is empty and you get the "Error in page" error. Double click the error and you get an Internet Explorer JS Error Window. Here it is in all its glory:

 image

 

How Do I Catch The Exception in Code?

The exception IS happening in code you're just not catching un-handled exceptions.

To turn them on, go to Debug --> Exceptions:

image

You'll get the window below. Check the "Common Language Runtime Exceptions" checkbox and click OK.

image

 

You will not get exceptions bubbled up to the Dev Environment. Here's what it looks like in action  (with the same error as the "blank screen" above).

image

 

Click "Break" and break into the area where the code barfed on you, and then clean up the mess you've created (on accident of course - who creates un-handled exceptions for fun anyway). :)

 

Enjoy.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | Visual Studio

TCCC 5 Interview on You Tube

by Donn Felker 16. November 2008 15:16

Back at the Twin Cities Code Camp I was interviewed by Jason Bock. He decided to post the interview on You Tube. If you want to hear me ramble on for almost 4 minutes you can do so by clicking the picture below. We go over my talk and some of my history of working at McFarlane Toys. Enjoy!

 

image

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Events

XamlParserException - AG_E_PARSER_BAD_TYPE

by Donn Felker 14. November 2008 04:11

Ohhhhh the dreaded XamlParserException. The exception message is not to helpful at all.

In my instance I was working with Silverlight. Namely working with the Prism  V2 Drop #5 from the Composite WPF team. Get the latest and read up the project here. I was loading the TreeView control into my view (Xaml) and when the app fired up the project would bomb with this exception and the message was VERY informative *sarcasm*.

AG_E_PARSER_BAD_TYPE

Hmm... Ok. Sure. Sounds good.

I have my projects laid out like so.

image

 

The Prism Shell (Top) loads different modules at runtime. Module A has a view (View 1) which has a tree view. Therefore, Module A (which is a Silverlight App itself) references the Microsoft.Windows.Controls library which contains the new controls for Silverlight (download them here). When this was getting compiled and referenced at runtime, the Microsoft.Windows.Controls dll was not in the Shell project, therefore it would blow up when it tried to parse the Xaml. Giving me the lovelly and dreaded XamlParserException.

The Fix

Simple. Add a reference to the Microsoft.Windows.Controls dll in the main Prism App. Then.... BLAMMO... the control toolkit works as expected. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight

Silverlight Cross Domain Issue

by Donn Felker 12. November 2008 07:31

I'm doing some Silverlight Development and I ran into a wacky issue (or so it seemed at the time).

The Silverlight app would connect to a Java Web Service and get some data (XML). The end result is that this Silverlight app will talk to Java Web Services and the xap file sit on a java web server and be downloaded to the client. During development its done on Windows Machines/VM's (of course). However, when we connected to the service, it would bomb with a Security Exception as follows:

 

A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll

Additional information: An error occurred while trying to make a request to URI 'http://example.org:7001/beans/TestWebServiceBean'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details.

At first glance this looks like an issue with the services clientaccesspolicy.xml file. But looking at the requests through fiddler or Web Dev Helper we can see that an HTTP success (200) was occurring for the requests of those files. They were coming back as expected.

 

CAS: True Smoke and Mirrors

The problem was due to the fact that we running Silverlight under the Test html page from the file system. So it would look something like this:

C:\SVNHome\path\to\project\Bin\Debug\TestPage.html

The Silverlight app would call a web service on the network or Internet. Them, BOOM all hell would break loose. Security exceptions flying around like snowflakes in Minnesnowta.

It looks like this was an issue with Code Access Security. Now I'm not exactly 100% sure where in the CAS stack this error occurred, but I do know that the local file was in a different zone than the Internet zone and when executing code in different zones you run into tons of CAS issues (SecurityExceptions). <Sarcasm>Read more about the super exciting world of CAS here </Sarcasm>. 


So I created a ASP.NET Web App and linked the Silverlight app with the Web App. I fired up the test page which now looks like this:

http://localhost:3399/SilverlightApplicationWevSvcTestTestPage.aspx

BOOM! The app worked just like it should have. Looks like a definite culprit of the deadly CAS. :)

:)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | WCF

Speaking at Twin Cities Developers Guild

by Donn Felker 6. November 2008 04:33

Its kind of last minute but I'll be speaking at the Twin Cities Developers Guild next Tuesday, November 11th. The meeting is located at New Horizons in Edina, MN. The exact address is: 4510 West 77th Street, Suite 210, Edina, MN 55435

Here's a Map:

Map image

Session Summary: Learn about how the Dependency Inversion Principle (DIP), Dependency Injection and Inversion of Control Containers help you get your system under test more effectively and how it can help you decouple your code. You will also be introduced to a small subset of dependency breaking techniques that will help you break ground into setting your system up for maintainability. This session is intended to be very audience interactive so that it can help the audience break into the world of dependency inversion and introduce methods that will help you gain confidence when you need to make a change in your code base.

 

See you there.

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Events

New GMail Mobile Version

by Donn Felker 6. November 2008 02:52

For those of you who use GMail mobile (as I do) there is a new version out. Go to http://m.google.com/mail to get it.

New Features

I'm not looking at the exact features, but these are the ones I noticed right away.

Pros

  • Account Switching - This is huge. I have multiple Gmail Accounts. The two I use most are my personal one and the one for my newsgroups. Normally on the phone I'd check one, log out, then log into the other one and read. It was kind of a pain, but it worked. Now you can just add multiple accounts and switch between them with a few clicks. AWESOME. 
  • Offline reading. I can open my email that I opened yesterday without being connected via the phone (if I have no signal I can still read some email)
  • Better interface - The scrolling is smooth. The error handling is a 'bit' better and the loading of the app initially is still great.

 

Cons

  • On my Windows Mobile 6 Device (T-Mobile Shadow) the app is STILL in JAVA. Come on now Google. ... you gave me a Google Maps app that runs as a Windows Mobile App. However you give me Gmail (which is used 10 times as much) and its in JAVA? In order to get to this I have to go to Apps, To Java, Start Java, Then Start Gmail, Then log in. Google Maps? Click the icon and go.  Simple.
  • Error Handling Sucks. Above I said it was better, but still.. it sucks. On a scale of 1-10, last version it was a -2, right now its a 1. Examples: Sometimes I'll send an email and it will just crash the app. Click send == SUPER FAIL. If I click on a link in an email Windows Mobile will raise a warning informing you that it may cost money if you don't have an unlimited data plan (I have unlimited so it didnt matter) ... but... I decided I didnt want to load the link anyway so I clicked no and got a Java Exception that hung the app. I reloaded it again and tried the same exact operation, yup, same error. FAIL.
  • The Address book is COMPLETELY BROKEN on two letter keyboards (shown below). If I add a recipient via the address book and type 4 for "D or F" (which is what I would expect as this is how the keyboard is laid out) I get "G, H or I". What the hell?  Apparently the app is hard coded to treat all keyboards as if they were a normal phone. A normal phone's #4's letter combo is "GHI". So that's very frustrating. Its unusable.

tmobile_shadow_keyboard

Even though there are some very frustrating items with Gmail Mobile, its support for threaded conversations is the real reason I use it. If Microsoft every developed a Threaded conversation that mimicked Gmails, hmmm... I might have to kiss Gmail good bye.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Misc | Productivity

How To: Implement a simple REST Services in WCF 3.5 Part 1

by Donn Felker 3. November 2008 11:03

What is REST?

A REST web service is a service that embraces "Representational State Transfer". What does this mean? Lets take a gander at the Wikipedia entry:

...

REST strictly refers to a collection of network architecture principles which outline how resources are defined and addressed. The term is often used in a looser sense to describe any simple interface which transmits domain-specific data over HTTP without an additional messaging layer such as SOAP or session tracking via HTTP cookies.

... (Source)

 

A simple ScreenCast illustrates this the best:

image

 

A Simple Example of REST Services

If I were using a REST service I would go to http://www.example.com/GetGasPrice/For/Zipcode/55402/ and the response would be a small POX (Plain old Xml) chunk that represents the price of gas at ZipCode 55402. Replace the "55402" with "96032" and you'll get the gas price for zipcode 96032.

Here is what we would see on the screen:

image

Plain Ol' Xml is being returned for our query. I can use .NET, PHP, C++, Ruby, Java, you name it, and we could parse this and move on with our application. REST is very interoperable.

 

This type of URL Scheming is very easy for users to understand as its following a Representational format. We're representing what we want to do in the form of the Uri. It's simple and easy to read. I can even access it via my web browser! We can change the zipcode from 55402 to 55401 and get a different price behind the scenes. Awesome.

However, this is not the only benefit of REST. There are many benefits of REST which are well beyond the scope of this introductory article. To learn more, read the wikipedia entry. In this article We're going to cover HOW to implement a rest service in WCF 3.5.

 

How To Implement REST Services

Note: If you want to go straight to the code, scroll down a bit. The full code project is zipped up and also available for download as well at the bottom of the post.

 

The Web Programming Model

We will cover the most common and basic use of a REST service, the GET. However, we will glance over the other topics as well.

WCF Provides a REST Programming model for us to use . The following classes are of great intestest when programming REST services. 

 

WebGetAttribute 

The WebGet attribute allows us to specify how we want to handle GET HTTP Verbs for processing the REST service. As the examples shows,  we are performing a GET on the URL and we're expecting some POX results back.

The code for that WCF Operation Contract looks like this:

 

        [OperationContract]
        [WebGet
            (RequestFormat = WebMessageFormat.Xml,
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/GetGasPrice/For/ZipCode/{zipCode}"
            )]
        GasPriceData GetPriceData(string zipCode);

 

RequestFormat is the format the request is made in. the two options are XML and JSON. If you request from the browser your request will still be honored.

ResponseFormat is the format that will be returned. The two options are XML and JSON. Here we are specifying that we would like to have XML returned to us.

BodyStyle represents how we want the data returned. Do we want the bare XML or the full "wrapped" XML?

Bare: 

<GasPriceData>
    <GasStation>Super America</GasStation>
    <Price>2.05</Price>
</GasPriceData>

Wrapped:

<GetPriceDataResponse>
    <GetPriceDataResult>
        <a:GasStation>Super America</a:GasStation>
        <a:Price>2.05</a:Price>
    </GetPriceDataResult>
</GetPriceDataResponse>

UriTemplate describes how we are going to handle the Uri mapping. In this case we are stating that from the BaseAddress we are going to have a url that looks like the following: /GetGasPrice/For/ZipCode/{zipCode}. This Uri is going to map to the method "GetPriceData(string zipCode)". The varibale in the UriTemplate - "{zipCode}" maps to the parameter in the method which is also called "zipCode". We have now abstracted our method call to utilize a Representational format of Uri.

If we wanted, we could change the UriTemplate to something like this: "/GetGasPrice/For/Some/Other/Long/Path/To/The/ZipCode/{zipCode}" and in the URL of your service you would access it like this:

- http://www.example.com/GetGasPrice/For/Some/Long/Path/To/The/ZipCode/55402

This would execute the GetPriceData method at this location.

 

WebHttpBinding - This is best put by the MSDN doc, so I'm going to quote them:

The WebHttpBinding incorporates support for XML, JSON, and raw binary data using the WebMessageEncodingBindingElement. It is composed of an HttpsTransportBindingElement, an HttpTransportBindingElement and a WebHttpSecurity object. The WebHttpBinding is designed to be used in conjunction with the WebHttpBehavior.

WebServiceHost - Another one that the MSDN doc covers better than I could:

WebServiceHost extends the ServiceHost to make it easier to host a non-SOAP Web-style service. If WebServiceHost finds no endpoints in the service description, it automatically creates a default endpoint at the service's base address. When creating a default HTTP endpoint, the WebServiceHost also disables the HTTP Help page and the Web Services Description Language (WSDL) GET functionality so the metadata endpoint does not interfere with the default HTTP endpoint. WebServiceHost also ensures that all endpoints that use WebHttpBinding have the required WebHttpBehavior attached. Finally, WebServiceHost automatically configures the endpoint's binding to work with the associated Internet Information Services (IIS) security settings when used in a secure virtual directory.

 

The Code

IGasPriceService.cs

using System.ServiceModel;
using System.ServiceModel.Web;
using Part1.GasService;

namespace Part1.GasService
{
    [ServiceContract]
    public interface IGasPriceService
    {
        [OperationContract]
        [WebGet
            (ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/GetGasPrice/For/ZipCode/{zipCode}"
            )]
        GasPriceData GetPriceData(string zipCode);

        [OperationContract]
        [WebGet
            (RequestFormat = WebMessageFormat.Xml,
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/GetGasPrice/For/City/{city}"
            )]
        GasPriceData GetPriceDataForCity(string city);
    }
}

This code explained ...

This is the Service Contract which implements two methods for our REST service. One that will get gas prices by city name and one that will get it by ZipCode.

 

GasPriceService.cs

using Part1.GasService;

namespace Part1.GasService
{
    public class GasPriceService : IGasPriceService
    {
        #region IGasPriceService Members

        public GasPriceData GetPriceData(string zipCode)
        {
            switch (zipCode)
            {
                case "00000":
                    return new GasPriceData { GasStation = "None", Price = 0.00m };
                case "55410":
                    return new GasPriceData {GasStation = "Holiday", Price = 1.99m};
                case "55404":
                    return new GasPriceData {GasStation = "Costco", Price = 1.79m};
                case "55412":
                    return new GasPriceData {GasStation = "Sams Club", Price = 2.79m};
                default:
                    return new GasPriceData {GasStation = "Super America", Price = 2.05m};
            }
        }

        public GasPriceData GetPriceDataForCity(string city)
        {
            switch (city.ToLower())
            {
                case "minneapolis":
                    return new GasPriceData { GasStation = "Super America", Price = 1.87m };
                case "stpaul":
                    return new GasPriceData { GasStation = "Holiday", Price = 1.99m };
                case "edina":
                    return new GasPriceData { GasStation = "Costco", Price = 1.79m };
                case "bloomington":
                case "richfield":
                case "woodbury":
                    return new GasPriceData { GasStation = "Sams Club", Price = 2.79m };
                case "shakopee":
                    return new GasPriceData { GasStation = "BP", Price = 4.39m };
                default:
                    return new GasPriceData { GasStation = "Super America", Price = 2.05m };
            }
        }

        #endregion
    }
}

This code explained ...

This is a quick hack to get data back to the service. In a real world scenario this would connect to some data store which would return the data. You would also probably want to cache this data for a short period of time to allow for more throughput throughout your system.

 

GasPriceData.cs

using System.Runtime.Serialization;

namespace Part1.GasService
{
    [DataContract]
    public class GasPriceData
    {
        [DataMember]
        public string GasStation { get; set; }

        [DataMember]
        public decimal Price { get; set; }
    }
}

This code explained ...  

This is the complex type that represents the Gas Price Data itself. Again, in a real service this would be implemented as a more robust object model. This is for example purposes only.

 

ExampleWebHost.cs

using System;
using System.ServiceModel.Web;
using Part1.GasService;

namespace Part1
{
    public class ExampleWebHost
    {
        public static void Main()
        {
            using (var gasPriceServiceHost = new WebServiceHost(typeof (GasPriceService)))
            {
                gasPriceServiceHost.Open();

                Console.WriteLine("The Base Address for the Gas Price Service is: {0}",gasPriceServiceHost.BaseAddresses[0].AbsoluteUri);
                Console.WriteLine("The service is now active. To terminate, press .");

                Console.ReadLine();
            }
        }
    }
}

This code explained ...

This code self hosts the WCF service and waits for a user to terminate it in a console window.

app.config



  
    
      
      
        
          
            
          
        
        
      
    
  

 

 

This code explained ...  

We are merely setting a base address and telling WCF to use the WebHttpBinding. The WebServiceHost takes care of the remaining config GOO that we would normally have to deal with. (how nice).


Starting Up The Service

Make sure your service is set to start as a console app and start up a new instance. At this time you should be able to access the REST service from your local host by sending a command to it like this:

image

The base address is "http://localhost:7002/ and then the UriTemplate is appended to that, making the full REST URL.

Clicking Enter, you will get your XML results. :)

 

Possibilities: Extending your Solution

As you've seen in the code, you can also implement extend your functionality in REST services by allowing users to find the gas price for a given city:

image

 

Conclusion

It's fairly simple to implement a WCF REST Service. Simply use the WebGet attribute, the Web Service host and the binding and you're off to the races. Next topic: Other HTTP Verbs with WCF Rest Services (Part 2).

 

Downloads

Project File and Classes Part1.zip (~8.5kb)

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

WCF

Disabling/Turn off the WcfSvcHost Test Client in VS2008

by Donn Felker 2. November 2008 14:16

This pertains to non-sp1. If you have SP1 installed there "should" be an option to disable it in the gui. This is from what I've read on the web. I don't have an SP1 machine in front of me so I'm posting this so I can find it later. If it helps you, then hallelujah

Here is what the test client looks like in your tray when it starts:

image

 

To disable the Test WCF Client (WcfTestClient.exe / WcfSvcHost) that comes with VS2008 you have to edit the goop that is the Project file.

Delete the following GUID from the PropertyGroup as shown below: {3D9AD99F-2412-4246-B90B-4EAA41C64699}

 

image

If you have the project open in Visual Studio it will ask you to reload it. Reload the project and you should be able to use whatever your service host implementation is.

Doing this will turn off the default test client. This was VERY problematic for me today while doing some proof of concept WCF REST implementations.

 

More on the WCF REST stuff soon. I can't believe how simple it is. The examples I found were not too intiutive so I'll type up a quick and easy tutorial that covers the GET and PUT http verbs.

Coming soon!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

WCF

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Donn Felker

Senior Consultant
MCTS
ScrumMaster
Agile Practitioner

About Me | Books I Recommend

Gotta Pay The Bills


Tag cloud

    Popular Posts

    RecentComments

    Comment RSS

    Calendar

    <<  January 2009  >>
    MoTuWeThFrSaSu
    2930311234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    View posts in large calendar