RSS2.0

Debugging Visual Studio Generated Strongly Typed DataSet Code

Tuesday, March 4, 2008

Sometimes you may face a situation when you need to debug Visual Studio generated code. For example, when you create strongly typed DataSets, Visual Studio generates corresponding code.

If you put a break point in such code, to your surprise the debugger will not fire it. This happens because the v2.0 CLR debugging services has a feature called Just-My-Code (JMC for short) debugging. By default this is enabled in Visual Studio. Hence, all code (methods) marked with System.Diagnostics.DebuggerNonUserCodeAttribute will be ignored by the debugger and no break points set in such code will be fired.

This is a pretty nice feature to avoid needless stepping in 3rd party code and Visual Studio generated code as well. However, as mentioned above, sometimes we need exactly the opposite, i.e. to be able to debug the Visual Studio generated code.

You can disabled JMC in Visual Studio options as shown on the screen shot below. Simply, clear the Enable Just My Code (Managed only) check box.


Mike Stall has a pretty nice article about JMC in his blog, which you can find here: http://blogs.msdn.com/jmstall/archive/2004/12/31/344832.aspx

Building Facebook Applications with ASP.NET

Sunday, January 20, 2008

I have recently started playing with the Facebook platform. The more familiar I become with developing for the Facebook platform, the more excited I get.

With the release of the Facebook Developer Toolkit by Clarity Consulting, Facebook development for .NET programmers has become very comfortable. I've been developing for the Microsoft .NET platform for several years and it was nice to learn that I could leverage this knowledge and experience when developing for Facebook.

It must be noted that I was able to get the IFRAME version of the Facebook application working immediately. However, I had been struggling exactly a day to get the FBML version of my "Hello World" Facebook application working.

To help fellow programmers, I have created a very simple Facebook application. The Visual Studio 2005 project can be downloaded from here: http://www.snapdrive.net/files/349810/MyFacebookApp.zip.

My application is located at: http://apps.facebook.com/facebookdemoapp and a screen-shot of it is shown below. As you can see, for now the application doesn't do much. It just greets a Facebook user.



The screen-shots below show exact settings of the application in the Facebook application settings. Important changes are given in red circles and I have added some comments in red color as well.

Base Options



Installation Options



Integration Points



In order to get your ASP.NET based Facebook application working, obviously you will need an ASP.NET hosting.

The only problem that I see now is debugging the application. However, I have solved this problem. Not a very elegant solution, but gets the job done. More about it will be addressed in the next post.

So, stay tuned and don't forget to subscribe to my RSS feed.

Enabling HTTP POST for an ASP.NET Web Service

Tuesday, January 8, 2008

If you have been working with ASP.NET web services, you might have noticed that on your local or development server, the web service exposes its methods via several ways (HTTP SOAP, HTTP Get, HTTP Post). Moreover, for those methods that accept parameters, the page displays HTTP Post form, which allows you to quickly test the web service.

However, when you deploy the web service, the only available methods for calling it is HTTP Soap. What if you need to allow HTTP Get and Post calls?

It turns out to be quite easy. Moreover, you can enable/disable protocols for a whole machine or for specific webservices. However, please keep in mind that enabling GET and POST protocols adds security risks. At least that's what Microsoft says. Technically, I don't think there is a considerable risk associated with enabling Post calls. Anyway, if you don't really need POST calls, then it's better to keep it disabled.

So, how do we do that anyway? Glad you asked. Look at the configurations below.

To enable HTTP GET and HTTP POST protocols for the whole machine:

Open the Machine.config file in a text editor. This file as rule lives in the \Config subdirectory of the installation root.

Add the following configuration between and tags.


<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
<add name="HttpPostLocalhost"/>
</protocols>
</webServices>
Save Machine.config.

This configuration change takes effect on the next request to a Web service hosted on that machine.


To enable support for a protocol for an individual Web application:

Open the Web.config file in the root directory of the Web application in a text editor.

Add the following configuration between and tags.

<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
<add name="HttpPostLocalhost"/>
</protocols>
</webServices>
Save Web.config.

This configuration change takes effect on the next request to a Web service hosted by the Web application.

Visual Studio 2008 Arrives on Time

Tuesday, November 20, 2007

One of my colleagues told me today that we was downloading Visual Studio 2008. To tell the truth I was somewhat puzzled. I did not expect Microsoft to release VS on time. So, after two years from release of Visual Studio 2005 we have Visual Studio 2008 codenamed Orcas. Visual Studio 2008 is available for immediate download for MSDN subscribers.

According to Microsoft's corporate vice president Somasegar (a.k.a "Soma"), Visual Studio 2008 contains over 250 new features.

Some of the most important new features include new visual designers like .NET Framework 3.5 components (Windows Presentation Foundation components, Windows Workflow Foundation components and Windows Communication Foundation components), workflow enabled services, multitargeting, LINQ and many others.

The Global Launch of Windows Server 2008, Visual Studio 2008 and SQL Server 2008 will take place on Feb. 27, 2008.

You can read the full interview with Soma at http://www.microsoft.com/presspass/features/2007/nov07/11-19developerqa.mspx

Simultaneously Calling Several Asynchronous Web Service Methods

Saturday, November 10, 2007

It's no more a secret that web services have become extremely popular past couple of years. Many distributed applications contain web services as a part of the solution. Even if your solution does not need a web service, you may need to consume a third party web service at some point.

C#/.NET makes it easy both creating your own web service and consuming either your own or a third party web service. As you may already know, you can call web service methods either synchronously or asynchronously. Frequently, asynchronous method of calling web service methods is a preferred way. Generally, when possible, I do use asynchronous calls.

Currently, I'm working on a project that heavily uses web services. At one point I ran in a situation where I needed to call multiple web service methods simulatenously. Development of the web service and the consumer application goes in parallel. Naturally, before consuming a web service method, we do test the web service. Suddenly, a strange exception started occurring when we were asynchronously calling two web service methods at the same time. The exception message is given below and you can see it in the screen shot.


Exception has been thrown by the target of an invocation.

InnerException

"There was an error during asynchronous processing. Unique state object is required for multiple asynchronous simultaneous operations to be outstanding."

When I checked the web service methods, they both worked without any problems.

It looks like that when we call several web service methods asynchronously, we need to somehow differentiate the calls. If you provide unique UserState objects to the calls, then this exception does not occur. But what shall we do if we do not need to use UserState objects at all? I have simply solved this by supplying a dummy user state object.

Look at the code fragment below. m_WSController is the instance of the web service class. Here I call two methods asynchronously:

GetPaymentMethodsAsync and GetUserPaymentDetailsAsync. Notice that adding a simple new object() dummy user state object solves the problem.

// THIS DOES NOT WORK

m_WSController = new MyApp.WebService.Controller();

m_WSController.GetUserPaymentDetailsCompleted += new MyApp.WebService.GetUserPaymentDetailsCompletedEventHandler(m_WSController_GetUserPaymentDetailsCompleted);
m_WSController.GetPaymentMethodsCompleted += new MyApp.WebService.GetPaymentMethodsCompletedEventHandler(m_WSController_GetPaymentMethodsCompleted);

m_WSController.GetPaymentMethodsAsync();
m_WSController.GetUserPaymentDetailsAsync(m_SessionId);

// THIS WORKS!


m_WSController = new MyApp.WebService.Controller();

m_WSController.GetUserPaymentDetailsCompleted += new MyApp.WebService.GetUserPaymentDetailsCompletedEventHandler(m_WSController_GetUserPaymentDetailsCompleted);
m_WSController.GetPaymentMethodsCompleted += new MyApp.WebService.GetPaymentMethodsCompletedEventHandler(m_WSController_GetPaymentMethodsCompleted);

m_WSController.GetPaymentMethodsAsync(new object());
m_WSController.GetUserPaymentDetailsAsync(m_SessionId);


Hopefully, this saves you time when getting the above described exception.

Drag-and-Drop Not working When Debugging in Visual Studio Under Windows Vista

Tuesday, October 30, 2007

There are many programmers out there working on real-world applications who have not programmed drag-and-drop functionality. However, sooner or later, you will need this nice feature of Windows (and GUI in general).

Adding drag-and-drop support to your application is not difficult in C#/.NET. However, when it comes to debugging drag-and-drop under Windows Vista that's when trouble begins. If drag-and-drop does work fine when you run the application from Explorer but does not when you run from Visual Studio 2005 don't be surprised. We will demystify this quickly. However, I must admit that it took me about and hour to figure out what was wrong.

As you are well aware, under Windows Vista, we usually work from a low privilege account. However, because this causes some problems when working in Visual Studio, most of the programmers run Visual Studio with Administrator privileges. It turns out that Windows Vista does not allow drag-and-drop operation if you are dragging from a lower privilege application to one with administrator privileges. So now it's easy to explain the strange behaviour.

When you start the application in a debug mode, Visual Studio has administrator privileges and if you try to drag-and-drop say from your desktop (which most likely has low privileges) the operation fails. Visual Studio would not even fire the drag-and-drop events.

So, what do we do when we need to run Visual Studio under administrator privileges and yet be able to debug drag-and-drop? Well, now when we have demystified the strange behaviour, we can solve this problem. This is how I solved this. I use Total Commander as my File Manager. So I run both Total Commander and Visual Studio with administrator privileges and drag-and-drop debugging works just fine.

Happy programming!

More cool posts coming soon.

Connecting SQL Server Management Studio to a Non-standard TCP/IP Port

Saturday, October 27, 2007

Microsoft SQL Server listens for incoming connections on a particular port. The default port for SQL Server is 1433. However, it doesn't need to be 1433.

It is a bit tricky to connect to the SQL Server running on a non-standard port. When connecting to the SQL Server running on a non-standard port, many people instinctively try to specify the server address in a IP:PORT format. Unfortunately, this doesn't work.

In order to connect to an SQL Server running on a non-standard port, you must specify the server address in a IP,PORT format. For example, if the IP address of the server is 235.12.175.96 and the SQL Server listens to 1037 port, you must specify 235.12.175.96,1037 as the server name.