Blog comments edit

A few days ago I saw a clip of PDC 2008 about MVC .Net which is great concept. It was performed by Phil Haack. In this video Phil shows a trick of Visual studio which is very useful.

Most of the time during application development you want use a class which its name space has not been included. Guess what should you do? Oh yes ! You should type name space completely or leave current line and go to top of class adding appropriate "using" statement get back to your line of code. Surprisingly there is a trick in visual studio 2008 (I tested in visual studio 2008). If reference of class included in project you can Type class name completely at the same time a tooltip bar will be appeared under your class name. At the same time press Ctrl+. (dot). A menu will be appeared which offers you two options. First option will add using statement at the top of code class file. Second option will insert full class name including name space.

![](http://5thrqg.bay.livefilestore.com/y1p0snTWe1Jg0ugeUDe89nhOn2YbMiAlN6FcMjO__gEFz_q1Mo0rDlMufKV5eAlHEz5RVV1wSEobfvnPOlDhber45OImXQZvGu-/CtrlDot.jpg?psid=1) ![kick it on DotNetKicks.com](http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fahmadreza.com%2fgf%2fblog%2fvisual-studio-trick-adding-namespace%2f)

Blog comments edit

Axum has been released in Microsoft DevLabs

What is Axum:

Axum is a language that builds upon the architecture of the Web and principles of isolation, actors, and message-passing to increase application safety, responsiveness, scalability, and developer productivity.

**Axum aims to validate a safe and productive parallel programming model for .NET.

you can find more inforamtion about Axum here

And here is Axum blog

Articles comments edit

This article is an attempt to depict steps may needed to configure IIS for hosting WCF application. An important thing that should be considered  is that all user do not face following situations. First of all I try to create a simple WCF application and then I try to publish this simple WCF simple application.

In order to create a WCF application we just need to know ABC of WCF application which are Address, Binding and Contract. (You can download code from [here](http://localhost/be/admin/Pages/resources/WCFConfigIIS/AccountSolution.zip))

First of all I created a blank solution with Visual Studio 2008 by clicking File > New > Project and selecting Other Project Types > Visual Studio Solutions > Blank Solution

I created solution named AccountSolution. I added new project named **Accounting **by right clicking on AccountingSolution and selecting Add > New project menu. In the next step I added reference of System.ServiceModel to project references.

I changed name of class1.cs to IAccount.cs and I added new class named AccountService.cs. Here is code for IAccount and AccountService: IAccount.cs

[sourcecode language="csharp"] using System; using System.Text; using System.ServiceModel; namespace Accounting { [ServiceContract] public interface IAccount { [OperationContract] int GetBalance(int accountNumber); } }[/sourcecode] </pre>
  AccountService.cs
[sourcecode language="csharp"]
using System;
using System.Text;
using System.ServiceModel;
 
namespace Accounting
{
    public class AccountService : IAccount
    {
        #region IAccount Members
 
        public int GetBalance(int accountNumber)
        {
            Random rnd = new Random(1000000);
            return Convert.ToInt32(rnd.Next());
        }
 
        #endregion
    }
}[/sourcecode]

 

I added new web site named WCFServiceAccount and added new project reference of Accounting. Since I added project reference to Accounting project, cs under App_Data folder is no longer needed. So let delete two cs file under App_Data.

 

![](http://gkasoq.bay.livefilestore.com/y1plDs_sJrdofjmxAJx5KLB1IRyo8OQaej-EbkO50xRPY-imFFs90p8YcQSZyn_32U0clWyp_dGQuQPHeD8T2wk4VK1hJPUhpQz/DeleteServiceFile.jpg?psid=1)

I changed Service.svc source to:

<%@ ServiceHost Language="C#" Debug="true" Service="Accounting.AccountService"%>

Setting Service and end points:

In order to setService and end points I used WCF Configuration option by right-clicking on web.config.

**Tip**: Sometimes "Edit WCF Configuration" does not appear in right-click menu. Once open "WCF Service Configuration" from tools menu and close it, this cause menu appear next time in right click menu.

I set first service name to Accounting.AccountService by browsing Accounting.dll in bin directory.

![](http://public.bay.livefilestore.com/y1pB_4Kia8qCvnVm84Z_mAPdTLsttzeYRSgavEDmipD1J2TQnRIww9aCgWUtkzJgmgjbpYQ4AJ-X6_t_fQTagoemg/WCFConf1.jpg?psid=1)

And I set first end point contract attribute to Accounting.IAccount and delete second end point.

![](http://public.bay.livefilestore.com/y1pNQJ7zjCYsuC64j1u4mzjceRtIOIUwlgh5uoo41IKuJ8l1aAoJRut7RFqtruUwN9nmq2lzezxzG81uNdDPTbGCA/WCFConf2.jpg?psid=1)

And at last save the WCF configuration and build solution. Before running web site let set WCFServiceAccount as startup project and set Service.svc as start page. Our web site is ready to be executed. After successful execution let host our website to local IIS. Simply website could be hosted by publishing web site to local IIS. If IIS is installed before visual studio 2008 you may not face with any following errors and simply you can jump next step.

I tried to publish WCFServiceAccount by right clicking on Web site project and selecting "…" then Local IIS but I've got following errors. (My windows was Vista Ultimate)

To Access local IIS Web sites, you must install the following IIS component. * IIS 6 Metabase and IIS 6 Configuration Compatibility * ASP.NET * Windows Authentication ![](http://public.bay.livefilestore.com/y1pTZqdAli9pFNV3Ue4EJsjyy7yxI73MHpJ2qV7eQ4t1HetvropmejZs60FD3KRdvxQHYuUzqycVYL_ZiuLoGGF1g/LocalIIS.jpg?psid=1)

Configuring IIS to publish a web site (Specially WCF web site):

To rectify mentioned errors I've found a document in [Technet](http://technet.microsoft.com/en-us/library/bb397374.aspx) for installing IIS6 Metabase and IIS 6 Configuration

To install the IIS 6.0 Management Compatibility Components by using the Windows Vista Control Panel 1. Click Start, click Control Panel, click Programs and Features, and then click Turn Windows features on or off. 2. Open Internet Information Services. 3. Open Web Management Tools. 4. Open IIS 6.0 Management Compatibility. 5. Select the check boxes for IIS 6 Metabase and IIS 6 configuration compatibility and IIS 6 Management Console. 6. Click OK.

Pasted from <[http://technet.microsoft.com/en-us/library/bb397374.aspx](http://technet.microsoft.com/en-us/library/bb397374.aspx)>

Following image shows how to install "IIS6 Metabase and IIS 6 Configuration ". Surprisingly you can set other option such as Installing ASP.NET and Windows Authentication.

![](http://public.bay.livefilestore.com/y1p98ev7XdDN9VOCAtu6E64aR9cfG1_-lRJRZk1r9BzkreaCp8mrRiBVTmCrdjkV88tdxHH926kCoEiQjtb9yEIkw/WindowsFeatures2.jpg?psid=1)

Alternatively, For installing ASP.NET you can use visual studio command prompt and running aspnet_regiis with -i parameter:

aspnet_regiis -i
 
Publishing WCFServiceAccount to local IIS:
1. Right click on WCFServiceAccount select publish from menu  ![](http://public.bay.livefilestore.com/y1psS3DvG852bzs4I8falh5ecsbtliNY19pE18ZF-zi6SMa9U3wOybrBRvrJ_QbUaTjWZs--NNgKBV-3f_CWAYTPw/PublishWebSite.gif?psid=1) 2. Select local IIS option 3. Select create new application icon 4. Type web application (e.g. WCFServiceAccount)  ![](http://public.bay.livefilestore.com/y1p8G2-IOJpyazU2KdzmRewVDyxiiFsckgqy4jdyopSmKNsJq3f5uv67yZ1YuKnhkPSEh9EU7wc_iRy3VBExsMQjg/PublishWebSiteIIS.gif?psid=1) 5. Now open a browser to test your application "http://localhost/WCFServiceAccount/Service.svc" 6. Then select Open button If you get following error:
# Server Error in '/WCFServiceAccount' Application.
# ## *Configuration Error* **Description: **An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.**Parser Error Message: **Unrecognized configuration section system.serviceModel. **Source Error:**
Line 101:
Line 102:
Line 103: Line 104:
Line 105:

              </td>
            </tr>
          </tbody></table>

        

**Source File: **C:\inetpub\wwwroot\WCFServiceAccount\web.config**    Line: **103


        
**Version Information:** Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053   </td> </tr> </tbody></table> OR

Server Error in Application "Default Web Site/WCFServiceAccount"

HTTP Error 404.3 - Not Found

Description: The page you are requesting cannot be served because of the Multipurpose Internet Mail Extensions (MIME) map policy that is configured on the Web server. The page you requested has a file name extension that is not recognized, and is not allowed.

Error Code: 0x80070032

Notification: ExecuteRequestHandler

Module: StaticFileModule

Requested URL: [http://localhost:80/WCFServiceAccount/Service.svc](http://localhost/DerivativeCalculator/Service.svc)

Physical Path: E:\Projects\Learning\Blog\WCFServiceAcount\Service.svc

Logon User: Anonymous

Logon Method: Anonymous

Handler: StaticFile

Most likely causes: * It is possible that a handler mapping is missing. By default, the static file handler processes all content. * The feature you are trying to use may not be installed. * The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)

What you can try: * In system.webServer/handlers: * Ensure that the expected handler for the current page is mapped. * Pay careful attention to preconditions (e.g. runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool. * Pay careful attention to typographical errors in the expected handler line. * Please verify that the feature you are trying to use is installed. * Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe. 1. Open a command prompt and change directory to %windir%\system32\inetsrv. 2. To set a MIME type, use the following syntax: appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string'] 3. The variable fileExtension string is the file name extension and the variable mimeType string is the file type description. 4. For example, to add a MIME map for a file which has the extension ".xyz", type the following at the command prompt, and then press Enter: 5. appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain'] Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. Determine if clients can download these file types before enabling them. * Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

More Information...This error occurs when the file extension of the requested URL is for a MIME type that is not configured on the server. You can add a MIME type for the file extension for files that are not dynamic scripting pages, database, or configuration files. Process those file types using a handler. You should not allows direct downloads of dynamic scripting pages, database or configuration files.

Server Version Information: Internet Information Services 7.0. </td> </tr> </tbody></table> You should register service model according to following steps: 1.

Run a Visual studio Command prompt 2.

Enter "cd c:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\" And press enter 3. Run "servicemodelreg -i"

Blog comments edit

During developing applications we have always use unwritten rule in programming or if it is written in design documents user should consider them in development. For example if developer wants to call a method which has an integer parameter and this parameter is used as an index of array he should be aware calling that method with negative value or greater than array lenght. Calling method with negative value causes runtime error.

There are lots of contracts that a developer should consider during development. Recently I came across new concept (However it is in research phase) named CodeContracts which is really wonderful. It seems that this concept will be in VS 2010. CodeContracts will organized all written and unwritten rules & contract in development. In order to clarify CodeContract usage imagine following code:  

[sourcecode language="csharp"] static void Swap(string[] arr, int itemIndex1, int itemIndex2) { string temp; temp = arr[itemIndex1]; arr[itemIndex1] = arr[itemIndex2]; arr[itemIndex2] = temp; } [/sourcecode] </pre>
What are possible errors when we want to call Swap method? * None of itemIndex1 and itemIndex2 could be negative (both should be positive) * None of itemIndex1 and itemIndex2 could be greater than arr.length * Array arr should be not null Before code contracts developer should always consider possible situation and avoid breaking rule. But CodeContracts provides rich methods by which you can add your Code Contracts to your method and after compiling application Contracts checker will warn about breaking rules. Let see how it should be implemented with CodeContracts
[sourcecode language="csharp"]
static void Swap(string[] arr, int itemIndex1, int itemIndex2)
{
     Contract.Requires(arr != null);
     Contract.Requires(itemIndex1 >= 0);
     Contract.Requires(itemIndex1 < arr.Length);
     Contract.Requires(itemIndex2 >= 0);
     Contract.Requires(itemIndex2 < arr.Length);

      string temp;
     temp = arr[itemIndex1];
     arr[itemIndex1] = arr[itemIndex2];
     arr[itemIndex2] = temp; 
} [/sourcecode]

</div>

 

I added five contracts to this method which mean this method needs not null array as first parameter, second and third parameter (itemIndex1, itemIndex2) should be greater or equal to zero and should be less than array length.

In the next post I will show how to implement this with CodeContracts

But now I want to introduce some resources: * Microsoft Research - Code Contracts home page * Tutorial Video in channel9 * Contract Checking and Automated Test Generation with Pex ![kick it on DotNetKicks.com](http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fahmadreza.com%2fgf%2fblog%2fcode-contracts-part-1-introduction%2f)

Blog comments edit

Graffiti CMS express edition is popular amid developers as well as Community Server. At the moment I wanted to decide between Graffiti And Community Server  I couldn't made my mind. Blog subsystem of community server has a simple theme which is similar to MSDN blog theme (Like current theme). This theme was inducement of community server. Finally, I used graffiti because of simplicity, anyway , Recently I decided to convert simple theme of community server 2008 to graffiti CMS theme.

I put first version of simple theme [here](http://gkasoq.bay.livefilestore.com/y1pkcDCK8ftzzfzO_6UO7nvtklXqCwp8FPSD2Tp_Lj3_7WVvfN_YWXQX5DBuXKoWFPiX8yUuyvqx96dLHR7MiWKIw/Simple.zip?download&psid=1)

Blog comments edit

SQL Server 2005 is installed without any samples - at least versions I installed don’t contain Northwind and pubs databases -. However Microsoft put SQL Server 2005 Samples and Sample Databases in Codeplex, light version of these two sample databases were always famous in a way that you can find one of them in most database related samples with high probability.  You can find SQL Server 2000 Sample here. After installation file is downloaded take following two steps:

1. Install msi file. Some files will be copied in C:\SQL Server 2000 Sample Databases 2. Attach Northwind.mdf file which is located in C:\SQL Server 2000 Sample Databases. Repeat this step for pubs mdf file.

Blog comments edit

Informing user about application state is one of important aspects in user experience. In windows applications mouse icon indicates one of great application states. When an application is busy mouse icon should be changed to wait cursor mode or hourglass icon. In windows application you can achieve this by changing Cursor property of any Control, Usually by changing "this.Cursor" which "this" is current form in application. See example:

 

this.Cursor = Cursors.WaitCursor;

 

Since control class in compact framework does not have Cursor property, not only developer could not change every control cursor icon but also he could not change form cursor property. So what should developer do in order to indicate application state?

There is a static class in System.Windows.Forms named Cursor and it has a property named "Current" which developer should set it to an appropriate cursor based on application state.

 

 

System.Windows.Forms.Cursor = Cursors.WaitCursor;

Or

System.Windows.Forms.Cursor = Cursors.Default;

Blog comments edit

After long absence I'm back now. Recently I wanted to develop an application for windows mobile with .Net Compact framework. In this application I need to measure elapsed time in millisecond resolution. First of all like everyone I tried to use Millisecond property of DateTime.Now static class. But it won't work at all in .Net Compact framework even in version 3.5!

If you want to use a timer with millisecond resolution you have to use TickCount property of Environment class.

//Will be zero.

lblMillisecondVal.Text = DateTime.Now.Millisecond.ToString();

//Total milliseconds elapsed since the system started.

lblTickCountVal.Text = Environment.TickCount.ToString();

[Here](http://gkasoq.bay.livefilestore.com/y1p-j36TiPUqAUB6w5kYE05nlr4sJQ6zrqwpr1ggB654bL0E7JHIehasbHjEaireeiTg9vR_nxCaAskngmyKX-o1Q/TickCountTest.zip?download&psid=1) is an example of using TickCount Instead of Milliseconds

Blog comments edit

Currently, I'm working on Pocket PC development. During last week I've found interesting resources about windows mobile development with .Net compact framework. first of all [Windows Mobile Team Blog ](http://blogs.msdn.com/windowsmobile/)would be a sophisticated resource. Moreover you could find other useful links in this weblog.

Other blogger's web site would be good resources, like [Chris Craft's Blog](http://www.cjcraft.com/blog/default.aspx). CJ's weblog contains a series of posts for a month. For each day he wrote a post about windows mobile programming. It would be a good starting tutorial for beginners.

Another web site that could be useful is [www.dotnetfordevices.com](http://www.dotnetfordevices.com/) .

However, I'll post related news and experiences during windows mobile development

Blog comments edit

Embedding other resources like Cascade style sheets and images is possible as well as JavaScript file. I wrote "[How to embed JavaScript file in an assembly](How-to-embed-JavaScript-file-in-an-assembly.aspx)" in previous post. For embedding images you have to do same way with minor changes in accessing resource. You should add you file into your project and

change the value of "Build Action" property to "Embedded Resource".  In Assembly info file you should add following line for images into AssemblyInfo.cs file:

 

[assembly: System.Web.UI.WebResource("EmbededJSControl.Logo.GIF", "img/gif")]

 

And following line for css file:

 

[assembly: System.Web.UI.WebResource("EmbededJSControl.Stylesheet.css", "text/css")]

 

To use image resource in your pages you should add following code. In case you use resource in same project you could use this.GetType() as first parameter otherwise you should create an instance of control from project in which you included resource and get type of that control.

 

Image img = new Image();

img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "EmbededJSControl.Logo.GIF");

For including stylesheet use following code:

 

string cssLink = "";

string location = Page.ClientScript.GetWebResourceUrl(this.GetType(), "EmbededJSControl.Stylesheet.css");

LiteralControl css = new LiteralControl(String.Format(cssLink, location));

Page.Header.Controls.Add(css);

 

Complete sample code is available [here](http://gkasoq.bay.livefilestore.com/y1peTj3VAMB0CgQFtkrQCdRlXxnjvPJ5t6Pzku8YfWyuUSFx9bGusFmlFhOIFBGBtVtjShgUOybQp1UYCkvcTEkjw/EmbededJSSource2.zip?download&psid=1) ![kick it on DotNetKicks.com](http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fahmadreza.com%2fgf%2fblog%2fhow-to-embed-other-resources-like-image-and-css%2f)

Blog comments edit

Developing ASP.NET web controls is always interlocked with creating javascript codes in order to create client side functions. Moreover, a developer always has a tendency to release minimum files, most of the time an assembly (DLL) which includes all requirements for web control, is best case. This post is an attempt to represent how to embed JS file in an assembly.

First of all you have to create an ASP.Net AJAX-Enabled Web Site  named "EmbededJSTest" and add System.Web.Extensions references to project . In order to add this assembly you have to install  [here](http://gkasoq.bay.livefilestore.com/y1pO5bR_q-B4Gz19EwxN2gjcNqm0xRMq64po2ycqOa-zoYFEVBhWwwCf89HGOy1pG6mYpaTfRL5XLM8ZSQUVyJ7DplFAfYtZJII/EmbededJSSource.zip?download&psid=1)

Blog comments edit

I had many experiences in different projects to create installation with “Wise Installation System Professional 9.0” especially in visual basic 6.0 projects. This version was extremely mach with visual basic 6.0 projects and its scripting was easier than that of competitive products.

Recently I was looking for a reliable packaging software and predictably I went in for new version of Wise installation express “ .At the beginning I wanted to evaluate “ Wise installation studio “ It was frustrating! because at the beginning it was a little complicated, However, I know that it is designed for an enterprise system development and it is more than an installer editor for medium-sized projects. I have historic problem with “express editions” which remind me limited features of an application. But “ Wise Installation Express 7.0 “ is something else and it seems more than an express edition of Wise installation and It will completely useful in small and medium-sized projects specially in windows applications. I’ve found it simple, easy to use and sophisticated. You can find full feature comparison grid here but for me highlighted features are listed below:

Wise Installation Studio/Express 7.0 Advantages from my point of view

  • Interface key-points is same as previous versions
  • Supporting Microsoft Windows Installer (msi)
  • Support for 64-bit installations
  • Support mobile device packaging
  • Supporting Merge modules
  • Patch Wizard

Blog comments edit

Although it wasn’t easy for me, finally I made up my mind to create a web log and write my experience and note about .Net issues and development. As far as I concerned many problems I’m recently grappling with are solved by blogs either I previously know or I find in search engines. Since give-and-take is one of basic rules in technical societies, taking advantage of others blogs without giving information does not seem fair. Hopefully, I’ll do my best to submit some useful post.

Moreover, I am enthusiastically looking for your comments and I believe that your comments will help me in order to improve my blog.