March 2009 - Posts

Insomnia? So.. take REST!

If you are getting insomnia then you need to REST.  For all types of insomnia (transient, acute, chronic), you need to take REST for a while. Yes, I will do later. But the REST is actually the one who made me insomnia.

I will post more after taking some rest, but for know, you can try to look on it:

- WCF REST Starter Kit
- A Guide to Designing and Building RESTful Web Services with WCF 3.5
- ADO.NET Data Services and Entity Framework How do I videos

Enjoy!

Cheers - RAM

Share this post: | | | |

FastCGI Application on Windows Azure

FastCGI is a protocol for interfacing interactive programs with a web server like IIS. It is a variation of earlier Common Gateway Interface (CGI) and very useful to reduce the overhead associated with interfacing the IIS and CGI programs, allowing a server to handle more web page requests at once. Instead of creating a new process for every request, FastCGI can use a single persistent process which handles many requests over its lifetime. Processing of multiple requests simultaneously is achieved either by using a single connection with internal multiplexing (ie. multiple requests over a single connection) and/or by using multiple connections. Many such processes can exist, something that can increase stability and scalability, read more at Wikipedia and its original spec.

FastCGI is language and platform independent protocol (but mostly C/C++ in nature). Not too much development at protocol level of FastCGI as it is very stable protocol, but it can be use in many web application scenarios because it ca add two new benefits that can boost scalability and availability:

- Distributed computing: run FastCGI applications on a different machine
- Multiple and extensible roles: CGI applications compute the response to an HTTP request.

In this post, I will explain how to develop FastCGI on Windows Azure using C++. I took a simple FastCFI sample from Windows Azure SDK March 2009 CTP. The sample program is designed to run as a sub-process of a Windows Azure Web or Worker role. It is a simple web role that demonstrates running a FastCGI application. By reading this post, you will understand how to:

- Enabling native code execution within the service definition file
- Configuring FastCGI in the web.roleConfig file
- Calling the Microsoft Service Hosting Runtime Native Library from a native C++ code

Note:  You can use MS C/C++ compiler and MSBUild to compile.
           All the command scripts are ready in the sample. Or using VC++ build project. 

01  02

The FastCGIApplication in this sample is pretty simple. It logs information and read configuration settings by calling Microsoft Service Hosting Runtime Native Library (msshrt.lib and ServiceHosting.h). The Service Hosting Runtime Native Library provides a native API for interacting with the role management agent and with the local storage resource in the Windows Azure environment or in the development fabric. You have to make sure Microsoft Service Hosting Runtime Native Library installed in you machine, usually at :

C:\Program Files\Windows Azure SDK\v1.0\

Its definition was located in FastCGIApplication.proj. If you are using x64 machine like me, you have to change the msshrt.lib location to (ServiceHostingSDKInstallPath)\lib\x64.

<PropertyGroup>
   <ServiceHostingSDKInstallPath Condition="'$(ServiceHostingSDKInstallPath)'==''">
$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v1.0@InstallPath)
</ServiceHostingSDKInstallPath> <ServiceHostingSDKInclude>%22$(ServiceHostingSDKInstallPath)\inc%22</ServiceHostingSDKInclude> <ServiceHostingSDKLib>%22$(ServiceHostingSDKInstallPath)\lib\x64\msshrt.lib%22</ServiceHostingSDKLib> <CPPCompiler>cl.exe /Zi</CPPCompiler> <OutputExe>FastCGIApplication.exe</OutputExe> </PropertyGroup>

03

Below is its main program:

#include "Common.h"
#include "FastCGI.h"
#include <stdio.h>
int __cdecl main(int argc, __in_ecount(argc) LPSTR argv[])
{
    Initialize();
    LogInformation("Starting FastCGI Processing");
    std::string msg = GetConfigurationSetting("MessageOfTheDay");
    FastCGI fastCGI(msg);
    fastCGI.ProcessRequests();
    LogInformation("Exited");
}

In the ProcessRequests(), this FastCGIApplication will calculte size of response based on information in message header, allocate memory for response,  and define response from FastCGI server.

void FastCGI::ProcessRequests()
{
    FCGI_Header headerOfMessage;
    FCGI_StdOutErrorRecord message_StdErr;

    DWORD dwBytesWritten = 0;
    DWORD dwError = 0;
    DWORD dwResponseSize  = 0;
    DWORD dwRequestId = 0;
    PBYTE pBuffer;
    HRESULT hr = S_OK;
    while ( TRUE )
    {                        
        ZeroMemory( &headerOfMessage, sizeof( headerOfMessage ) );
        Recieve((PBYTE)&headerOfMessage, sizeof(headerOfMessage) );
        
// Calculate size of response based on information in the message header dwResponseSize = ( headerOfMessage.contentLengthB1 << 8 ) + headerOfMessage.contentLengthB0 + headerOfMessage.paddingLength; if( dwResponseSize > 0 ) { // Allocate memory for response pBuffer = new BYTE[dwResponseSize + 1]; if ( NULL == pBuffer ) { dwError = ERROR_OUTOFMEMORY; Error("Could not allocate memory" ); } ZeroMemory( pBuffer, dwResponseSize ); Recieve(pBuffer, dwResponseSize ); } dwRequestId = (headerOfMessage.requestIdB1 << 8) + headerOfMessage.requestIdB0;
        // Switch based on header type and define your own response to each of the 
//
messages from the FastCGI Server switch( headerOfMessage.type ) { case FCGI_BEGIN_REQUEST : LogVerbose("FCGI_BEGIN_REQUEST"); break; case FCGI_PARAMS : LogVerbose("FCGI_PARAMS"); break; case FCGI_STDIN : LogVerbose("FCGI_STDIN"); ProcessRequest(dwRequestId); break; case FCGI_NULL_REQUEST_ID : LogVerbose("FCGI_NULL_REQUEST_ID" ); break; default : Error("Unhandled type obtained, quitting" ); break; } } //end while }

If you are using VC++, you can build the FastCGIApplication and debug your FastCGI_WebRole project. Make sure the the WebRole project has web.configrole where application full path is defined. Note that %RoleRoot% is point to the root of your WebRole project, the same location with web.configrole and web.config files:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
    <fastCgi>
      <application fullPath="%RoleRoot%\FastCGIApplication.exe"/>
    </fastCgi>
  </system.webServer>
</configuration>

Ok, other thing that you should check is your web.config file. Make sure you have defaultDocument pointed to index.htm and has mapped the path of FastCGIApplication.exe.

<?xml version="1.0"?>
<configuration>
  <system.web>
   <compilation debug="true"/>
  </system.web>
  <system.webServer>
    <!-- Setup index.htm as a default document. -->
    <defaultDocument>
      <files>
        <add value="index.htm"/>
      </files>
    </defaultDocument>
    
    <!-- Map a particular path to our FastCGI application. -->
    <handlers>
      <add name="FastCGI Sample" 
           path="MessageOfTheDay" 
           verb="*" 
           modules="FastCgiModule" 
           scriptProcessor="%RoleRoot%\FastCGIApplication.exe" 
           resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>


Now let see what is inside the index.htm. It basically a simple HTML page with a link to MessageOfTheDay. There is no page like that, because FastCGIApplication.exe is the interpreter who will response to the HTTP request.

<h1>A FastCGI Application</h1>
    The path <a href="MessageOfTheDay">MessageOfTheDay</a> is an example FastCGI application.
    The applications use the native runtime API to log information 
    and read configuration settings. After clicking on this page you can examine the logs 
    to see information about the handling of the request.

05
06

Ok, now let give more instances in Service configuration file (<Instances count="4"/>) then debug the WebRole project to see the local development fabric.

07

Want to see this application running in cloud? Simple, right click on the FastCGI web role project, then click publish. Visual Studio will create a ready to deploy package for you (fastcgi.cspkg and serviceconfiguration.cscfg) then redirect your browser to Windows Azure cloud provisioning site. You will need .NET passport and Azure invitation code to get access to that site. I create my FastCGI project there and deploy the FastCGI application in 4 steps:


1. Create a new project
08

2. Set the hosted service name (URL)

09

3. Prepare a staging deployment

10

4. Upload the project package and service configuration

11

Make sure that everything is well deployed. Azure use an effective way of HTTP deployment. 
 12

For more information about deploying your package and developing on Windows Azure, I would like to recommend you the "How Do I?" Videos for the Azure Services Platform. Enjoy!

Hope this helps!

Cheer – RAM

Share this post: | | | |

PHP FastCGI on Windows Azure

After downloading the latest Azure Developer Kits (March 2009 CTP), I am very excited to let you know that Windows Azure offers native code execution, including support for FastCGI and full trust. As developers, we can choose to write services in a native language such as C or C++ and publish them to Windows Azure in the same manner as any other service, but to be more specific, below is its native execution supports:

- Windows Azure supports the IIS 7.0 FastCGI module.
- We can host web roles that require an native interpreter like PHP.
- We can host web roles and worker roles written in managed code under Windows Azure full trust.
- A role running under full trust can call .NET libraries, read the local server registry, and call native code libraries.
- We can develop a service in native code and test and publish this service to Windows Azure.
- A role running native code can interact with the Windows Azure runtime

Sure, I will show you how to start working with PHP in Windows Azure. What you need to do before being able to follow this article is (I assumed you already have VS 2008 SP1 installed):

- Install the Hotfix: Support for FastCGI on Development Fabric
- Install the Hotfix: Native Debugging Improvements
- Install the Hotfix: Improve Visual Studio Stability
- Install the Windows Azure SDK (March 2009 CTP)
- Install the Windows Azure Tools for VS 2008 (March 09 CTP)

If you have installed previous version of Windows Azure SDK and Tools, please un-install it before then install the hotfixes before the new Windows Azure SDK and Tools. If you are done, you can move forward.


Hosting FastCGI Applications

Windows Azure supports IIS 7.0 FastCGI module, so we can host web roles that call applications written in native interpreted languages, such as PHP. To host a web role that runs FastCGI on Windows Azure, we will follow the steps below.

First, create a Cloud Service - Web Cloud Service project in VS 2008, then go to Service Definition file to set the enableNativeCodeExecution attribute to true. It will look like this:

01

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="PHPAzure" 
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WebRole name="WebRole" enableNativeCodeExecution ="true"> <InputEndpoints> <!-- Must use port 80 for http and port 443 for https when running in the cloud --> <InputEndpoint name="HttpIn" protocol="http" port="80" /> </InputEndpoints> </WebRole> </ServiceDefinition>


To enable FastCGI, add a web.roleConfig file in the root of the Web Role project, and specify which FastCGI application we will be using.  Please Note that web.roleConfig is an optional file; it's only needed if we wish to enable FastCGI. After add web.roleConfig file, specify the absolute path to the PHP FastCGI application (php-cgi.exe).

To specify the absolute path, precede the interpreter file name with the %RoleRoot% environment variable. The %RoleRoot% variable returns the absolute path to the directory in which the role is running. This directory corresponds to the root of web role project, the same location as the project's web.config file and the web.roleConfig file. Below is the config for PHP FastCGI application:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
    <fastCgi>
      <application fullPath="%RoleRoot%\php\php-cgi.exe"/>
    </fastCgi>
  </system.webServer>
</configuration

Note: The FastCGI application must be xcopy-deployable and contained in our project.  In this case, it is in the “php” subdirectory and specified via the special %RoleRoot% environment variable.  An xcopy-deployable version of PHP for Windows can be downloaded from http://php.net. After downloaded, extract it do the %RoleRoot%.

Once enabled FastCGI, we need to configure handlers for a web role running a PHP FastCGI application by adding them to the system.webServer section of our project's web.config file. The FastCGI module will then handle each *.php request type. To add handlers to the project's web.config file, locate the handlers element of the system.webServer element, and add PHP handlers within this section. Below is our web.config file looks like after modified to handle .php file extension :

<?xmlversion="1.0"?>
<
configuration>
  <
system.webServer>
    <
handlers>
      <
addname="PHP via FastCGI"
           path="*.php"
           verb="*"
           modules="FastCgiModule"
           scriptProcessor="%RoleRoot%\php\php-cgi.exe"
           resourceType="Unspecified" />
    </
handlers>
  </
system.webServer>
</
configuration>

Now you are ready to create a PHP page. Lets make simple page using phpinfo().

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>PHP on Azure</title>
</head>

<body>
<?php phpinfo();?>

</body>

</html>

So our project will look like below:

04  06

Normally we should be able to invoke our FastCGI application using Visual Studio Debug Menu (Control-F5) and get the PHP welcome page.  If you prefer to try without Visual Studio, Ryan Dunn has provide this cool manual way using *.bat files.  You can change number of web role instances via a simple modification to the Service Configuration file <Instances count="3"/>, see get more scale.

Note : Becareful with some thread safe PHP extensions in you php.ini file, as it may cause APPCRASH like below. Let me know if you have this problem too.

02  03

For further exploration, I do recommend you this MIX 09 presentation : Building Web Application with Windows Azure. In his presentation, Steve Marx did a very cool PHP on Azure demo, Tweval. That is a real deployed PHP sample on Windows Azure.

07

Hope this helps!.

 

Cheers – RAM

Share this post: | | | |

Windows Filtering Platform

After read a blog post on LSP and WFP from Wiria, I can’t stop exploring it. Especially WFP, Windows Filtering Platform. Why it is so exciting? Read below:

WFP enables inspection and modification of stream and packet data coming in. A stream can be paused and later resumed; parts of the stream can be permitted, blocked or replaced with different data. There can be multiple stream modifiers performing stream modification. The stream can be pended if more data is needed to make a filtering decision on the stream. A typical use of this would be an application that needed to screen the stream for unwanted words.

Packet modification is also supported by different re-injection APIs. In this case, the packet is cloned, modified and re-injected either in the send, receive or forward path. Packet modification can involve header modification (e.g. port, source, destination addresses for NAT scenarios) or payload modification (both content and size can change). Packets can also be pended and then injected at a later time or discarded at a later time depending on the filtering policies. [Anupama Vasanth, WFP Automation Developer/Tester]


Yes, it provides rich filtering interface but at the same time it also exposes a new set of socket-level security APIs that enable Windows Sockets applications to leverage with IPsec for securing traffic.

Traditionally, IPsec has been used to protect network traffic via central administrative configuration using local or Active Directory group policy. The Secure Sockets API is an extension to the Windows Sockets API that allows socket applications to directly control security of their traffic over a network. The API extension allows applications to provide security policy and requirements for their traffic, and query the security settings applied on their traffic. For instance, applications can use this API to query a remote peer’s security token and use it to perform application-level access checks, or client applications can simply specify the Server Principal Name (SPN) of the server to prevent any man-in-the-middle attacks. Today, applications can already secure their traffic by using SSL, etc. But in comparison, the Winsock extension has been designed to make it very easy for a network application to secure its traffic, with minimal additional code, while letting Windows Sockets abstract away the complexity. [Kartik Murthy, IPsec Developer]


Windows Filtering Platform (WFP) is available on Windows Vista and Windows Server 2008. With WFP we can examine or modify outgoing and incoming packets before additional processing occurs. By accessing the TCP/IP processing path at different layers in the protocol stack, we can more easily create firewalls, antivirus software, diagnostic software, and other types of applications and services, that I mentioned to Wiria 8 months ago. Figure below showed the extensibility points of WFP that will be useful for third party ISV:

WFP_Arch

Below is collection of sample codes that will guide you how to use WFP with C++.

- Windows Filtering Platform Sample
- Firewall using Vista's Windows Filtering Platform APIs
- Windows Filtering Platform Stream Edit Sample
- Windows Filtering Platform MSN Messenger Monitor Sample
- Windows Filtering Platform Packet Modification Sample
- Windows Filtering Platform Traffic Inspection Sample

WFP will be more safe comparing to LSP. Enjoy the samples :)


Hope this helps – RAM

Share this post: | | | |

HIS 2009 Will Come

If you are not familiar with the Host Integration Server, you can learn from HIS official site. Currently there is a HIS 2009 RC version available from http://connect.microsoft.com/.  HIS 2009 is fully integrated to Visual Studio 2008. Last time I worked on HIS project for screen level interface to mainframe (2370 protocol) and I found that much more features will come from HIS 2009. Screencast from HIS team below is very useful to give you ideas on data and application level integration to host systems.

- Acessing Offline Mainframe VSAM Data Using Host Integration Server 2009 Release Candidate
- Exposing Mainframe Applications as SQL Stored Procedures using HIS 2009 Release Candidate

In case you have a specific integration case to legacy in AS400/MainFrame in your company, feel free to put in comment below.

Cheers - RAM

Share this post: | | | |

BizTalk 2009 Beta with Visual Studio 2008

Finally, BizTalk Server 2009 supports the latest Microsoft application platform technologies, including Windows Server 2008, Microsoft Visual Studio 2008 SP1, Microsoft SQL Server 2008 and the .NET Framework 3.5 SP1. BizTalk Server 2009 also delivers expanded new connectivity options including new integration with Oracle e-Business Suite, as well as updated platform support for the most recent versions of IBM  Customer Information Control System (CICS), Information Management System (IMS), DB2, DB2/400, DB2 Universal Database and WebSphere MQ. You can download BizTalk 2009 Beta Evaluation version at Connect.Microsoft.com.

01


BizTalk Server 2009 delivers improved scalability and reliability through support for SQL Server 2008, Windows Server 2008 Hyper-V virtualization and enhanced failover clustering. It also provides significant new enhancements to both individual and team productivity by enabling new interoperability with ALM solution: Visual Studio Team System and Team Foundation Server 2008. This allows development teams to utilize the integrated source control, bug tracking, team development support, Project Server integration, and support for automating builds via MSBuild for a more seamless development and testing experience.

In this post, I will guide you to install BizTalk 2009 Beta and start working with it using Visual Studio 2008. First, you have to download BizTalk 2009 with its components (UDDI services, adapter pack, accelerator) from connect website. Before you install BizTalk, I assumed you already have the following in your machine:

- OS                 : Win Svr 2008, or Vista SP1 with all critical updates.
- IIS                 : IIS 7.0
- VS 2008 SP1: Install C# or VB.NET
- SQL 2008     : Default installation. SQL 2005 is also applicable.
- Sharepoint    : WSS 3.0 SP1 or MOSS 2007 SP1

I am using Windows Server 2008 x-64 with VS 2008, SQL 2008 and MOSS 2007 installed.


Install BizTalk 2009

After installed IIS, VS 2008, SQL 2008 and Sharepoint (WSS/MOSS), you are ready to install BizTalk 2009. Remember that you also have to install BizTalk Redistribution Pack (download links for pre-downloaded CAB are listed in BizTalk 2009 installation guide) if some pre-requisites are not installed in your machine. 
03  05
In my case I installed all the BizTalk core components for single server installation including BAM, Dev Tools and SDK, Documentations, Server runtime and additional software. If everything ok with your installation, you can launch the BizTalk Server configuration wizard. But before we configure BizTalk, something need to be done.

06   07  

When using the SQL Server shared memory protocol with BizTalk Server 2009 you might experience degradation in performance under certain stress conditions, if clients are accessing SQL Server from the same computer. To resolve the problem you need to disable the use of the shared memory network protocol in the SQL Server Client Network Utility. After you disable the shared memory protocol, you will need to restart SQL Server services.


Configure BizTalk 2009

In this task, I will show you how to configure BizTalk Server 2009 using the Basic configuration option. Basic configuration is recommended for developers setting up a complete installation of BizTalk Server running on a single server. When configuring BizTalk Server 2009 using basic configuration, consider the following:

- Configuring a remote SQL Server is not supported.
- Configuring against SQL Server 2008 default instances and named instances is supported.
- Account you are logged on is local administrators and have System Administrator rights on SQL Server.
- The account you are logged on must be a member of the OLAP Administrators on the OLAP box if configuring.
- You cannot configure BAM Analysis on a SQL Server named instance using basic configuration.

09 

When you use the basic configuration option, the following occurs:

- All database names are generated by BizTalk Server.
- All applicable database logon information is run under the account provided.
- All BizTalk Server services are generated by BizTalk Server.
- All BizTalk Server services run under the account provided.
- All features are configured based on the prerequisite software you have installed on the computer.
- The logged on user must be a member of the OLAP Administrators group on the OLAP server.
- The Default Web Site in Internet Information Services (IIS) is used for any feature that requires IIS.

The implication of the last point is we need to extend Default Website as a virtual server. WSS/MOSS uses virtual servers to host Web sites on server. The process of applying WSS/MOSS to a virtual server is called extending. We must extend a virtual server with WSS/MOSS before we can create a Web site based on WSS. We can do that in MOSS with the following steps:

- Go to Microsoft WSS/MOSS Central Administration.
- Navigate to the Application Management page.
- Under SharePoint Web Application Management, select Create or Extend Web Application.
- On the Create or Extend Web Application page, select Extend an existing Web application.
- On the Extend Web Application to Another IIS Web Site page, Select Change Web Application.
- On the Select Web Application page, select SharePoint Central Administration 3.0, and then click OK.
- In the IIS Web Site section, click Use an existing IIS Web site.
- Select Default Web Site.
- Leave the rest of the default values, and then click OK.


Work with Visual Studio 2008

BizTalk 2009 is fully integrated to Visual Studio 2008. To start with BizTalk project, you can open Visual Studio 2008 and create BizTalk empty project. All BizTalk project (Schema, Map, Pipeline, and Orchestration) will be compiled as .NET Assembly (DLL).

1011
I will not discuss about BizTalk development here, only to give you starting point on BizTalk 2009 and Visual Studio 2008. BizTalk Development tools provides Visual Studio templates and visual designers to enable developer working on schemas, mapping the schemas, and doing system workflow (orchestration) and defining send/receive pipelines.

12  13
Visual designers in BizTalk is just tools to make your life easier when dealing with the BizTalk APIs.

14    15

We will discuss more about BizTalk development in my incoming postings.

Stay tuned!

Hope this helps – RAM

Share this post: | | | |

EWS – Exchange Web Services

If you currently using legacy APIs in Exchange 2007 (CDOEX, WEBDAV, Event Sinks or Exchange OLEDB) for integration to LOB or 3rd party ISV applications, you can now try Exchange Web Services. Comparison between legacy APIs to EWS is explained here, including the Exchange 2007 Legacy API property mapping, for your migration purpose. 

LOB apps that use EWS can access data store items locally or remotely by using a SOAP version 1.1 (or 1.2). EWS is deployed with client access server role. Exchange Server 2007 clients connect to the server that is running Exchange 2007 that has the Client Access server role installed in an Active Directory directory service site by using an HTTPS connection. The target Client Access server obtains the information by communicating over MAPI to the Exchange server that has the Mailbox server role installed and then sends it back to the source Client Access server. If the target mailbox is in the same Active Directory site, the Client Access server uses MAPI to communicate with the Mailbox server to obtain the information. The Client Access server then provides the data back to the client.

How It Works
When a client application requests information from the Exchange store, an XML request message that complies with the SOAP standard is created and sent to the Exchange server. When the Microsoft Exchange server receives the request, it verifies the credentials that are provided by the client and automatically parses the XML for the requested data. The server then builds a SOAP response that contains XML data that represents the requested strongly typed objects and their properties. The XML data is sent back to the client application in an HTTP response. The client application then de-serializes the XML and uses the data to reform the strongly typed objects. You can read more on about EWS architecture from here as you have to understand some additional concepts like autodiscover service, event notification, delegate access and server-to-server authorization.

02

What in Exchange Web Services

EWS provides the functionality to enable client applications to communicate with the Exchange server. EWS provides access to much of the same data made available through Outlook, to enable LOB applications to have functionalities like Outlook. The Exchange Web Services clients can integrate Outlook data into Line-of-Business (LOB) applications. Exchange Web Services is described by three files that are located in the EWS virtual directory:

- Services.wsdl : contract between client and server.
- Messages.xsd : request and response SOAP messages.
- Types.xsd       : elements used in the SOAP messages.

Exchange Web Services provides the following types of operations:
- Availability
- Messaging Records Management
- Folder
- Item
- Utility
- Notification
- Synchronization

How to Start

You can download TechReady 2007 EWS Sample Codes to get started with EWS. Extract the installer then open EWSDemos.sln using Visual Studio 2005/2008. It will be better to use VS 2008 and .NET 3.5 as you can utilize new features like LINQ in your codes. To change the target WS from contoso.com, you can delete the existing WS proxy and add the new proxy based on your configuration.
07

Then you can start to explore the following demo applications:

- Auto Discovery Demo
- Availability Demo
- Create Meeting and Send Invitation Demo
- Pull Notification Demo 

08   09

Hope this helps!

Cheers – RAM

Share this post: | | | |

Whats New from MIX 09

MIX 09 just ended yesterday. That was the biggest web developer event from Microsoft this year. With 129 total sessions, this event brought new technologies like Silverlight 3.0, IIS 7.0 Media Services, ASP.NET MVC, IE 8, SQL Data Services (Astoria), Azure Service Platform, PHP on Windows, etc. I really suggest you to go the MIX 09 site and get all those technologies on your machine by clicking the picture below. You can click each session title then download all recorded videos and PPTs. Enjoy!. 

01 
Selamat ber web-ria :).


Cheers – RAM

Share this post: | | | |

Using SSIS with MySQL

This is a step by step guide for you to connect to MySQL and do SSIS data flow task to transfer data from/to SQL Server, or other RDBMS. You need SQL Server 2005/2008 with SSIS (SQL Server Integration Services) and BI development studio installed. Then install .NET Connector for MySQL, which is a standardize ADO.NET data provider for .NET.

1. Open Visual Studio and Create BI project – Integration Services Project
2. Add new data source for your MySQL (this can be data flow sources or destination)
3. Choose MySQL Data Provider (this is not ODBC) and configure/test your connection.
01  05

4. Configure your connection, pooling, security and some advanced properties.
03  04

5. Once your data source ready, now you can start to doing the SSIS package, for example Data flow task to transfer data from/to MySQL Database.

 06

Hope this helps – RAM

Share this post: | | | |

ADO.NET Data Service with MySQL

In this post, I will show you how to create ADO.NET Data Service from database using Entity Data Model. Instead of SQL Server, I will use WordPress database in MySQL 5.1. as example. You can follow with other database like Oracle. I will assume you already have WordPress installed in your machine. You will also need .NET Connector for MySQL.

1. Create Database Connection to WordPress DB in MySQL

We will add connection to the following database in MySQL.

03

Open Visual Studio 2008, in server explorer, add new data connection. Once you installed the .NET Connector, you can see option to connect to MySQL data provider as following. Then you have to provide some logon information as following.

08

2. Create a Entity Data Model

Create a ASP.NET Web Application in VS 2008 and add new Entity Data Model, let say WordPressDB.edmx. In the EDM Wizard, choose to generate from database and select your data connection that created in step 1.

05

Make sure you got all of the WordPress tables, but you dont have to select all, you can select for example only wp_users table.

09

Visual Studio 2008 SP1 will create the data model base on your selected table then generate data source class for your ADO.NET Data Services.

10 

3. Create ADO.NET Data Services

In this step you have to add new item – ADO.NET Data Services called WPUsers.svc and modify its data source according to your generated entity class name:

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;

namespace Astoria
{
    public class WPUsers : DataService<WPEntities>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(IDataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        }
    }
}

Now your ADO.NET Data Services is ready. You can test it using the REST query for example:

 http://localhost:12519/WPUsers.svc/:

11

Done! Now you are ready to learn how to consume the REST based ADO.NET Data Services, for example from PHP application. I will show you more in my next post, stay tuned!


Hope this helps - RAM

Share this post: | | | |

Web Slice and Feed Authentication

IE8 Gallery provides many Web Slice add-on that you may want to try. In this post, I will share about authentication feature in IE8 WebSlice. In many scenarios, for instance Banking application, authentication is required. The IE8 Windows RSS Platform now has support for HTTPS BASIC and HTTP/S DIGEST authentication.  This option is the only supported option for setting credentials for a feed or Web Slice via our new RSS authentication APIs, right click on the WebSlice and go to its property form.

11

Other authentication schemes Kerberos and NTLM for example should typically ‘just work’ as the OS will already handle these schemes and users will already be authenticated to these servers (e.g. by joining a computer to a domain over NTLM) and will only access those WebSlices or feeds when within that realm. 

Depends to our application requirements, each of the option has benefits and tradeoffs. We can also do the following authentication mechanisms in WebSlice:

1. Persistent login cookies (“remember me”) 
2. Web Slice specific auth cookie
3. Unique subscription URLs

I’m still looking my free time to look deeper on those concepts for PHP applications, as each application has different authentication mechanism. For now, you can warm up by reading Amy Placzkiewicz blog post in IE8 team blog:

WebSlice and Feed Authentication – Developer Guidelines

Hope this helps - RAM

Share this post: | | | |

PHP Interop via RESTful .NET Services

RESTful Web Services gains many attentions from web developers. As REST is an architectural style, it is not tied to one particular platform and technology. In .NET platform, we can play with “RESTful Services” with WCF 3.5 REST Starter Kit, ADO.NET Data Services, and Azure Service Platform. I found the following article and resource very useful for us to understand RESTful Services in .NET platform. You can also consult to some recommended books listed below.

A Guide to Designing and Building RESTful Web Services with WCF 3.5
Microsoft PDC 2008 Website – A lot of Azure and SQL Data Services info

With the advance of RESTful .NET, many other Web 2.0 framework like PHP will be benefited. For example, we can easily publish data services using ADO.NET Data Services, Entity Data Model and LINQ, hosted as HTTP services in IIS then consumed by PHP applications. With REST support in popular Zend framework and WSF/PHP, this “via REST interop” can help huge numbers of PHP developers to take advantages from RESTful innovations in .NET.

Test
REST01
REST02
REST03

Stay tuned, I will dive deeper into this PHP interop journey!


Hope this helps – RAM

Share this post: | | | |

Adding WebSlice in WordPress Site

A WebSlice uses a combination of the hAtom Microformat and the WebSlice format. By adding those three annotations, IE recognizes that it is a WebSlice and treats it like a feed; handling the discovery, subscription, and processing of the WebSlice. Actually it is easy to enable WebSlice in a site, we just need to add HTML annotations to the target webpage, for example:

<div class="hslice" id="kaskusitem555">
       <p class="entry-title">Kaskus Hottest Thread</p>
       <div class="entry-content">Kaskus Thread 
       …
      </div>
</div>

In this post, let see how to add A WebSlice in common PHP applications : Wordpress. You can also do the same experiment with other CMS like Joomla, Mambo, Drupal, PHPNuke, PHPBB etc. I used IIS 7.0, PHP FastCGI and MySQL in Windows Server 2008 to run WordPress. To Setup FastCGI for PHP on IIS and WordPress in IIS is out of scope of this post.

Practically to add WebSlice on WordPress site, what we will do is pretty simple:

- Modify the target page where we want to display the WebSlice icon, could be index.php or other landing pages.  
- Prepare a page to be displayed in the WebSlice or RSS feed. We can use css to manage the layout of the page.


Ok, lets create two files wp_webslice.css for WebSlice layout and for  wp_webslice.php data feed at the root directory of WordPress installation. Then add the following codes to index.php :

<div id="wpupdate" class="hslice" style="padding:8px 0px 0px;display:block">
    <div style="display:none;">
        <p class="entry-title">Risman Adnan WebSlice</p>

        <p class="entry-content">&nbsp;</p>
        <a href="wp_webslice.php" class="feedurl" rel="feedurl">&nbsp;</a>
    </div>
</div>

In the wp_webslice.css, write style to manage the layout of the WebSlice.

body {
    margin:0;
    padding:0;
    font-family: Georgia, Times, Times New Roman, sans-serif;
    font-size: 0.9em;
    text-align:left;
    color:#29303B;
    background: #FEFFA3;
}

ul {
padding-left: 9px;
margin-left: 0;
}

li {
    padding-left: 0px;
    margin-left: 0px;
    margin-bottom: 10px;
}

And in the wp_webslice.php, write PHP codes to query data from tablepost then display it in the WebSlice page. For example:

<?php
/* Don't remove this line. */
require('./wp-blog-header.php');
?>

<head>
    <title>Risman Adnan Webslice</title>
    <link rel="stylesheet" type="text/css" href="wp_webslice.css" media="screen" />
    <link rel="shortcut icon" href="icon.ico" />
</head>

<body>

<div id="wpupdate" class="hslice">
<h2 class="entry-title">Risman Adnan Blogs Update</h2>
<div class="entry-content">
<ul>

<?php

    function get_recent_posts ($num_posts = 5)
    {
    global $wpdb, $tableposts, $post, $tablepost2cat;

    if (!isset($tablepost2cat)) $tablepost2cat = $wpdb->post2cat;
     if (!isset($tableposts)) $tableposts = $wpdb->posts;

    $orderby = "$tableposts.post_$orderby";

    $now = current_time('mysql');
    $sql = "SELECT DISTINCT * FROM $tableposts ";
    $sql .= "WHERE $tableposts.post_date <= '$now' AND ( $tableposts.post_status = 'publish') ";
    $sql .= "GROUP BY $tableposts.ID ORDER BY $tableposts.post_date DESC";
    $sql .= " LIMIT 0, $num_posts";

    $posts = array();
    $posts = $wpdb->get_results($sql);
    if (empty($posts)) return;

    echo '<ul>';

    foreach ($posts as $post) {

     $title = the_title('', '', false);
     echo '<li>';
     echo '<a href="'.get_permalink().'" title="View Post '.htmlspecialchars(strip_tags($title)).'">'.$title.'</a>';
     echo '</li>';
    }

    echo '</ul>';

   } //end function get_recent_posts()

   get_recent_posts();
   ?>
   </ul>
   </li>   
</div></div>

</body>
</html>

And you are done! If everything works well, you will see the WebSlice icon when you open index.php.   

10

What about Joomla, PHPBB, Mambo, etc? I will post more about it. 


Hope this helps - RAM

Share this post: | | | |