Saturday, December 15, 2007

Exposing a BTS orchestration as a WCF service

Hey everyone, I've learened recently few new technologies that were just released and so decided to share some of the stuff that was hard to find on the web.

I'll start with Exposing a BizTalk orchestration as a WCF service, it's really simple but there are some problems that happened along the way.

1. First publish your orchestration as a WCF service

- open the “BizTalk WCF Service Publishing Wizard”

-Select your Http Binding
-Browse for your BizTalk application

-Browse for your BTS application dll.

-Type the name of your namespace.
-Type the name of the Service on the IIS.

2. After you finish you will have a WCF service created in your IIS.

3. Now you can “Browse” your WCF service normally as any webService.

4. Consuming your WCF service in a client application:

a. Open VS Command Prompt and type:
“svcutil.exe http://server2003sql:81/WCF_Service/DemoBTS_OrderProcessing_Order_RecievePort.svc?wsdl”
b. This will generate two files at the directory you are on, a configuration file “Output.config”; which contains the endpoint for your WCF service and a code file “BizTalkServiceInstance.cs”; that contains the client class (objects for your receive port and objects for your schemas).
c. Add the two files to your client application and use the generated client class to call the Service.

5. Submitting data from InfoPath to WCF service:
It’s the same as submitting to WebService, you can find its steps here:

  • Problem 1
An error occurred while browsing your WCF service from IIS and you can’t view the error.
1. Open the “web.config” file at “C:\Inetpub\wwwroot\WCF_Service”.
2. Uncomment the tag, now you’ll be able to view your error
  • Problem 2

The SOAP Adapter fails to register

The following error may occur when BizTalk Server attempts to register the SOAP (or HTTP) adapter.
"The Messaging Engine failed to register an adapter "SOAP" (Or "HTTP"). Details: "Registering multiple adapter types within the same process is not a supported scenario. For e.g. HTTP and SOAP receive adapters cannot co-exist in the same process".

When running BizTalk Server on Windows Server 2003 / IIS 6.x, the SOAP and HTTP adapters cannot execute in the same process space or application pool.
If an installation requires using both the SOAP and HTTP adapters on the same Web server then separate application pools must be created for each adapter. Once created, the virtual directories for each adapter are each assigned to a different application pool.

  • Problem 3

You forgot to assign the receive port of the orchestration to the generated receive port of the WCF service.
In the “BizTalk Server Administration” Tool >> Orchestration properties >> Bindings

Thursday, December 13, 2007

Code Snippets - Get the most out of them

Microsoft finally decided to help us remember some code using the code snippets, that was a new technique since Visual Studio 2005. Visual Studio 2005 came up with some built in code snippets too that I personally didn't find them as much useful as expected. However, later in October 2006, they produced a very nice and vast set of C# code snippets that you can download to integrate those already installed with Visual Studio 2005.
You can download it from this link:

As you can see below, these snippets have a wide range of functionality that we need in our daily programming activities. You no longer have to know how to Read Data from a Serial port or even compute the hashcode of a password. It's really a great one from Microsoft.

How to Add them?

  1. Well, first of all install the msi file that you downloaded from the URL above
  2. From the Visual Studio menu, choose Tools > Code Snippets Manager.

  3. Press the Add button from the dialog box that will appear

  4. When installing the code snippets package, it will copy all the snippets to My Documents\MSDN\Visual C# 2005 Code Snippets.
    so add this URL in the Browse dialog and press open.

Here you are, and you are done. Right click, Insert Snippet, and you will find the new Visual C# code Snippets appear.

Enjoy and Happy Programming ;)

Sunday, December 9, 2007

Make Pasting into Visual Studio Easier

Don't be limited to plain text. You can paste strings into Visual Studio as comments, string, StringBuilders, and more.

SmartPaster is a plug-in for Visual Studio .NET 2003 that allows text on the clipboard to be pasted in a format compatible with C# and Visual Basic code. SmartPaster can be downloaded from

After downloading and installing SmartPaster, you will see a new item on the right-click (context) menu

Paste as String/StringBuilder

I find myself most frequently pasting text as a string or a StringBuilder. You can copy any sort of text from another application, then when you paste that text into Visual Studio, you can choose to paste it as a string or as a StringBuilder.

Many developers like to build a SQL statement using a tool such as Query Analyzer, for easy testing and debugging, or Microsoft Access, for quick, visual development. As simple as it is to build queries externally, putting them into code can often be a challenge, especially when the queries span multiple lines. SmartPaster eases the task of bringing external queries to code: simply copy your query to the clipboard and paste as a string or StringBuilder. For example, if you copied the following SQL to your clipboard:


SELECT ProductName

FROM Products

ORDER BY Products.UnitPrice DESC

then paste the code into Visual Studio using Paste As String, you would see the following code:

@"SET ROWCOUNT 10" + Environment.NewLine +

@"SELECT ProductName" + Environment.NewLine +

@"FROM Products" + Environment.NewLine +

@"ORDER BY Products.UnitPrice DESC" + Environment.NewLine +


You could also paste this code using Paste As StringBuilder and specify a StringBuilder name of "sqlBuilder," and this would result in the following code:

StringBuilder sqlBuilder = new StringBuilder(141);

sqlBuilder.AppendFormat(@"SET ROWCOUNT 10{0}", Environment.NewLine);

sqlBuilder.AppendFormat(@"SELECT ProductName{0}", Environment.NewLine);

sqlBuilder.AppendFormat(@"FROM Products{0}", Environment.NewLine);

sqlBuilder.AppendFormat(@"ORDER BY Products.UnitPrice DESC");

Like SQL statements, text displayed to the user is often developed externally, either by a copywriter, business analyst, or coder (such as myself), and requires the spellchecker within Microsoft Word. Usually, pasting such code would require going character by character, escaping quotes, and manually adding in line breaks. With SmartPaster, a quick right-click, paste-as, and your external copy is now internal without any of the normal hassle.

In an ideal world, all messages and dialogs would be stored in an external resource file and all SQL statements would be in views and stored procedures. But in a world of deadlines and disposable microapplications, doing it the right way is often trumped by "make sure it works."

As we've seen, SmartPaster offers the option of pasting your text as a string or a StringBuilder. While the difference may seem cosmetic, there are actually appropriate times to use one over the other. The reasoning behind this is that string literals (i.e., strings explicitly declared in your code, as opposed to those input by the user) are immutable. This means that every operation on a string, such as a concatenation or replacement, involves creating an in-memory buffer, performing the operation, creating a new string, and finally passing the old one to garbage collection.

Knowing that, it's fairly easy to decide whether to use a string or a StringBuilder. If the text will always be static, such as a tool tip, there will be no advantage to using a StringBuilder (even if string literals are concatenated across lines, the compiler joins them in memory). However, if the text will vary on conditions, such as a runtime error message, then there will definitely be a performance hit using a string as opposed to a StringBuilder.

Paste as Comment

Just as with strings, any text on the clipboard may be pasted as a block of comments. I've found this very helpful in many cases. Having instant blocks of comments makes development much easier because of the following reasons:

  • Business rule requirements may be pasted directly into the code for easier translation and to explain what is being done.

  • Documentation from MSDN or other sources may be pasted in, avoiding the need to switch between the code and a browser window.

  • When upgrading code from another platform, the legacy code can be pasted as a comment, making it easier to ensure the logic is the same.

To paste text as a comment, you simply need to copy text to your clipboard and then choose Paste As Comment. For example, if you copied the following piece of text to your clipboard:

Call the test method to walk through this scenario and test every part.

and then pasted it into your document using Paste As Comment, you would see the following comment added:

//Call the test method to walk through this scenario and test every part.

Paste as Region

When pasting as a region, the clipboard text will simply appear between #region and #endregion tags with a region name of your choice. This feature is often helpful when organizing code within your application or pasting regions of code developed by someone else.

First, copy a piece of code like this one to your clipboard:

private void DoSomething( )


//Write Code Here


Then select Paste As Region, and a small dialog will appear.

From this dialog, you specify the name of the region that you want to use; after you click OK, this code will be pasted into your document:

#region DoSomething Method

private void DoSomething( )


//Write Code Here




SmartPaster offers a number of configuration options to make the add-in work best for you. The SmartPaster configuration can be accessed through Paste As Configure.

Wednesday, October 3, 2007

Force English DateTime format in Web Pages.

Many people argued that i usually add very lengthy posts here in my technical blog, which they think nobody will do read them. But actually, i am targetting in my posts those who are just beginners as well. So I will try my best to minimize everything as much as possible to be OK with everyone, and everybody is welcommed to ask as many questions as he/she wish and I will be answering them as soon as possible :).

Well this problem I will be mentioning now soon is very common especially for those who live in Arabic countries, as usually they configure their windows in the Regional and language settings to Arabic - [Country].

What's The problem?

The problem is that when you get to say

//Value -> 30/01/2006 10:33:00 م

As it's obvious, you may find instead of the AM and PM added at the end of the time, it became ص and م instead. The problem may further extend and sometimes you may find the monthe name became فبراير instead of February.
ok so what's the problem? well, if you have a field in the Database that is of DataType DateTime, and tried to insert any of the values mentioned above, you will get an error that says that the string is not a valid DateTime string.

How to Fix that?

The first thing that will come in your mind am sure, is to change the Regional and language settings in your windows configuration (Control Panel> Regional and language settings), and make everything point to United States.

This is not always the case, and wont always fix your problem. So here you are the clue. In your web Application, edit you web.config file if already available, or add it into your application, and add the following line in it.

<globalization requestEncoding="utf-8" responseEncoding="utf-8" uiCulture="en" culture="en-US" />

This forces the website to use the English Culture and the United States Configurations, not just in time formats, but in numbers, currencies, short and long dates. And this sure solves the problem perfectly.

Thursday, June 21, 2007

WPF Forms <---> Win32 Forms

As WPF becomes more and more popular nowadays, many people face the problem where they want to embed WPF pages in ordinary pages made in ordinary Win32 pages. Many reasons are there which make developers forced to think about it. Developers want to benefit from the extraordinary WPF benefits such as the flexible and amazing graphical user interface, ..etc. However, WPF can't do everything, as you can't for example create an extensibility project using WPF, you are still forced to use Win32 forms.

However, sometimes developers prefer using Win32 controls, because simply they are more than WPF controls. So here comes the need to embed Win32 forms in WPF forms.

These two walkthroughs are a very good reference for doing so, Thanks to MSDN

Walkthrough: Hosting a Windows Presentation Foundation Control in Windows Forms

Walkthrough: Hosting a Windows Forms Control in a Windows Presentation Foundation Page.

Sunday, May 20, 2007

Retrieving your Computer Information using WMI

Hey I am back again with a new post. Many people wonder how can I write a simple application that can tell me everything about my computer, my OS version, detect if I have a printer or not, ....... etc
Well, we will be using the WMI, Windows Management Windows Management Instrumentation. I believe the best way to discuss this topic is by observing the code directly as it is really simple to read and understand. Please feel free if you have any questions or comments to post them :)

Happy coding...

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace WMI
class Program
static void Main(string[] args)
// TODO: Add code to start application here
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)");
Console.WriteLine("Written By Ahmed IG -");
ManagementObjectSearcher query1 = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
ManagementObjectCollection queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
Console.WriteLine("Name : " + mo["name"].ToString());
Console.WriteLine("Version : " + mo["version"].ToString());
Console.WriteLine("Manufacturer : " + mo["Manufacturer"].ToString());
Console.WriteLine("Computer Name : " + mo["csname"].ToString());
Console.WriteLine("Windows Directory : " + mo["WindowsDirectory"].ToString());

query1 = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
Console.WriteLine("Manufacturer : " + mo["manufacturer"].ToString());
Console.WriteLine("Model : " + mo["model"].ToString());
Console.WriteLine("Total Physical Memory : " + mo["totalphysicalmemory"].ToString());

query1 = new ManagementObjectSearcher("SELECT * FROM Win32_processor");
queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)

query1 = new ManagementObjectSearcher("SELECT * FROM Win32_bios");
queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)

query1 = new ManagementObjectSearcher("SELECT * FROM Win32_timezone");
queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)


A good refrence about the available Win32 classes, please visit

Monday, April 9, 2007

Designing MasterPages

MasterPages, What are they? Lets first Imagine the case where you have to build a website. Of course, the design must be the same across all the pages, so what you will find yourself doing is, you will be copying the HTML code of the design in all pages, I.e. duplicate work! so what's the alternative way? MasterPages!

MasterPages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page. Sounds Cool right?

For more information about how MasterPages work, please visit this link

But, my aim in this post was not just introducing you to masterpages. I wanted to discuss the way of designing these masterpages because I faced a lot of trouble and problems when I just got started.

Professional designers use special tools like Adobe Image Ready to create nice designs, and cut the pics into boxes and tables. The Adobe Image Ready then can create an HTML page with a table and adjusting everything, images, background images, background colors,........etc. So what will you be doing is just replacing the masterpage HTML code with that you have in the HTML code you got from the Adobe Image Ready where it has all the code for all the content you made in your nice design. But please don't forget to add the following tags in the body section of the HTML code, and placing everything inside it.

<form id="form1" runat="server">


The reason for this tag is of course known, as if you didn't add these tags, and tried to put any server control in the page, these controls will throw an exception, saying "Control must be placed inside a form tag with runat="server"".

Here we come to the real problem where most of people suffer from. Lets see the case were we have a masterpage (Masterpage.master) and a content page (Default.aspx), where they are in the same directory

Everything will go really simple, cute and so smooth. No problems at all. in your content page (Default.aspx) you will find everything you placed in the masterpage. Lets first see the other situation and where the problem appears, then we will get to know what is the reason and how to solve it.

In this case, the content page (ForgotPassword.aspx) is in another subdirectory of that where we placed our masterpage. what you will usually find is that not everything you placed in the masterpage appears in your page, background images disappeared, images aren't there, and a red X mark appears instead. The only thing that acts normally is the background color.

At runtime, the master page and the content page are in the same control hierarchy – the master page is essentially a user control inside the content page. At design time, however, the master page and content page are two different entities. In fact, the master page and content page may live in different directories. During design time, it's easy to put URLs and relative paths into our master pages, but we have to be careful when using relative paths. Take the following master page excerpt as an example:

<img src="logo.gif" alt="Company Logo"

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

As long as the master page and the web form live in the same directory, the company logo will display in the browser. When the master page and web form live in different directories, the image will not appear. The browser requests knows nothing about master pages. The browser will interpret any relative paths it finds in the HTML as being relative to the webform. If our logo and master page files are in the root directory, but the web form is in a subdirectory, the browser will ask for logo.gif from the same subdirectory. The server will respond with a 404 (file not found) error.

The good news is, the ASP.NET runtime does provide a feature called “URL rebasing”. The runtime will try to “rebase” relative URLs it finds on server-side controls inside a master page. This means the following relative path will work, no matter where the master page and web form live.

<img src="logo.gif" alt="Company Logo" runat="server" />

We’ve added a runat=”server” attribute to the image tag, making the <img> a server-side control. When the master page file and logo are in the root directory, but the web form is in a subdirectory, the ASP.NET runtime will rebase the relative path it finds in the src attribute to point to the root of the website.

The following code will also work, because we are using a server-side Image object.

<asp:Image ImageUrl="logo.gif" runat="server" />

Now lets have a look at background images, as we have to act differently with them.

<body background="logo.gif" runat="server">
<!-- the background for the body tag will break -->
<form id="form1" runat="server">
<div id="Div1" style="background-image: url('logo.gif');" runat="server">
<!-- My background is also broken. -->

If you need to use a relative path in an area where the runtime does not provide the rebasing feature, you can compute a client side URL using ResolveClientUrl and passing a relative path. ResolveClientUrl, when called from inside a master page, will take into account the location of the master page, the location specified in the HTTP request, and the location specified by the relative path parameter to formulate the correct relative path to return.

<body background=<%= ResolveClientUrl("logo.gif") %> >

When working with image paths in embedded styles, it’s often a good idea to move the style definition into a .css file. The ASP.NET runtime will rebase the path it finds inside a link tag, so we won’t have any problems locating the stylesheet from any webform. Take the following style definition in a .css file:


Relative paths are safe inside a .css file because the browser will always request logo.gif relative to the location of the stylesheet.

Friday, April 6, 2007

My First Post

Hey Everybody, Thanks for visiting my Technical Blog first. ISA I will be posting here only technical issues, and maybe some useful posts. Hope everybody can benefit from it. See you soon with my next real TECHNICAL POST.