Monday, February 28, 2011

Some helpful REGEX (regular expressions for postal code, email, phone, SIN)

What are we cooking today?
Some REGEX (Regular Expresions) for:
  • Canadian/US Postal Code
  • Email (x@x.x)
  • Phone number (xxx)(xxx-xx-xx)
  • Canadian SIN (xxx-xxx-xxx)
Recipe

Valid Canada Postal Code
(^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$)

Valid US and Canada
(\d{5}(-\d{4})?)|(^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$) )

Valid Email
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Valid US Phone
((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}

Canadian SIN
\d{3}-\d{3}-\d{3}

Thursday, February 24, 2011

Tuesday, February 8, 2011

Troubleshooting a web service consuming app error

What are we cooking today?

Troubleshooting :
"Could not find default endpoint element that references contract in the ServiceModel client configuration section"

Recipe
  1. Imagine you want to consume a web service.
  2. You created a class that have the reference to the web service
  3. You created a website (consuming application) that use the class described in (2)
When you run the web app you get this message:
"Could not find default endpoint element that references contract in the ServiceModel client configuration section"

An easy solution that worked for me: Copy all  the content of the MyClassNamespace.dll.config when you compiled your class into the web.config file of the consuming application. (The objective is to expose the endpoint and the correct contract name)

Add to web.config

















Other possible solutions I found when searching:

a) Copy config file (MyApi.dll.config) from class library to bin folder of consuming application and rename it to MyApp.config

b) Programatically create instances of Binding and RemoteAddress objects and use the constructor that takes these 2 parameters