tag:blogger.com,1999:blog-56151467908667249942008-07-23T21:45:10.179-07:00Professional Software ProgrammingGeorge S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-5615146790866724994.post-17830049757007442692008-03-04T05:31:00.000-08:002008-03-04T06:36:17.562-08:00Debugging Visual Studio Generated Strongly Typed DataSet CodeSometimes 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.<br /><br />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.<br /><br />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.<br /><br />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.<br /><br /><a href="http://bp1.blogger.com/_UwePAMT2t7g/R81eKt8MZdI/AAAAAAAAAYc/NFZkd2ib8cg/s1600-h/just_my_code.gif" target="_blank"><img id="BLOGGER_PHOTO_ID_5173895085142336978" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_UwePAMT2t7g/R81eKt8MZdI/AAAAAAAAAYc/NFZkd2ib8cg/s400/just_my_code.gif" border="0" /></a><br />Mike Stall has a pretty nice article about JMC in his blog, which you can find here: <a href="http://blogs.msdn.com/jmstall/archive/2004/12/31/344832.aspx" target="_blank">http://blogs.msdn.com/jmstall/archive/2004/12/31/344832.aspx</a>George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-88965226283733741722008-01-20T12:06:00.000-08:002008-01-20T12:23:56.794-08:00Building Facebook Applications with ASP.NETI have recently started playing with the Facebook platform. The more familiar I become with developing for the Facebook platform, the more excited I get.<br /><br />With the release of the <a href="http://www.codeplex.com/FacebookToolkit" target="_blank">Facebook Developer Toolkit</a> 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.<br /><br />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.<br /><br />To help fellow programmers, I have created a very simple Facebook application. The Visual Studio 2005 project can be downloaded from here: <a href="http://www.snapdrive.net/files/349810/MyFacebookApp.zip" target="_blank">http://www.snapdrive.net/files/349810/MyFacebookApp.zip</a>.<br /><br />My application is located at: <a href="http://apps.facebook.com/facebookdemoapp" target="_blank">http://apps.facebook.com/facebookdemoapp</a> 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.<br /><br /><a href="http://bp1.blogger.com/_UwePAMT2t7g/R5Os5gl2iyI/AAAAAAAAAU4/92T1Rwk9rpI/s1600-h/Facebook_Screenshot1.gif" target="_blank"><img id="BLOGGER_PHOTO_ID_5157656102270569250" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_UwePAMT2t7g/R5Os5gl2iyI/AAAAAAAAAU4/92T1Rwk9rpI/s320/Facebook_Screenshot1.gif" border="0" /></a><br /><br />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.<br /><br /><b>Base Options</b><br /><br /><a href="http://bp2.blogger.com/_UwePAMT2t7g/R5Osnwl2ixI/AAAAAAAAAUw/ALOj9uD4X7A/s1600-h/BaseOptions.gif" target="_blank"><img id="BLOGGER_PHOTO_ID_5157655797327891218" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_UwePAMT2t7g/R5Osnwl2ixI/AAAAAAAAAUw/ALOj9uD4X7A/s320/BaseOptions.gif" border="0" /></a><br /><br /><b>Installation Options</b><br /><br /><a href="http://bp0.blogger.com/_UwePAMT2t7g/R5OrqQl2ivI/AAAAAAAAAUg/AHjx57h2Xjw/s1600-h/InstallationOptions.gif" target="_blank"><img id="BLOGGER_PHOTO_ID_5157654740765936370" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_UwePAMT2t7g/R5OrqQl2ivI/AAAAAAAAAUg/AHjx57h2Xjw/s320/InstallationOptions.gif" border="0" /></a><br /><br /><b>Integration Points</b><br /><br /><a href="http://bp2.blogger.com/_UwePAMT2t7g/R5Or8wl2iwI/AAAAAAAAAUo/fPLkHB5Rh2A/s1600-h/IntegrationPoints.gif" target="_blank"><img id="BLOGGER_PHOTO_ID_5157655058593516290" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_UwePAMT2t7g/R5Or8wl2iwI/AAAAAAAAAUo/fPLkHB5Rh2A/s320/IntegrationPoints.gif" border="0" /></a><br /><br />In order to get your ASP.NET based Facebook application working, obviously you will need an ASP.NET hosting.<br /><br />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.<br /><br />So, stay tuned and don't forget to <a href="http://www.prosoftprogramming.com/feeds/posts/default" target="_blank">subscribe to my RSS feed</a>.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-57172493228870593182008-01-08T02:28:00.000-08:002008-01-08T02:50:03.144-08:00Enabling HTTP POST for an ASP.NET Web ServiceIf 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.<br /><br />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?<br /><br />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.<br /><br />So, how do we do that anyway? Glad you asked. Look at the configurations below.<br /><br /><strong>To enable HTTP GET and HTTP POST protocols for the whole machine:</strong><br /><br />Open the Machine.config file in a text editor. This file as rule lives in the \Config subdirectory of the installation root.<br /><br />Add the following configuration between <system.web>and </SYSTEM.WEB>tags.<br /><br /><br /><pre>&lt;webServices&gt;<br /> &lt;protocols&gt;<br /> &lt;add name="HttpSoap"/&gt;<br /> &lt;add name="HttpPost"/&gt;<br /> &lt;add name="HttpGet"/&gt;<br /> &lt;add name="Documentation"/&gt;<br /> &lt;add name="HttpPostLocalhost"/&gt;<br /> &lt;/protocols&gt;<br />&lt;/webServices&gt;</pre>Save Machine.config.<br /><br />This configuration change takes effect on the next request to a Web service hosted on that machine.<br /><br /><br /><strong>To enable support for a protocol for an individual Web application:</strong><br /><br />Open the Web.config file in the root directory of the Web application in a text editor.<br /><br />Add the following configuration between <system.web>and </SYSTEM.WEB>tags.<br /><br /><pre>&lt;webServices&gt;<br /> &lt;protocols&gt;<br /> &lt;add name="HttpSoap"/&gt;<br /> &lt;add name="HttpPost"/&gt;<br /> &lt;add name="HttpGet"/&gt;<br /> &lt;add name="Documentation"/&gt;<br /> &lt;add name="HttpPostLocalhost"/&gt;<br /> &lt;/protocols&gt;<br />&lt;/webServices&gt;</pre>Save Web.config.<br /><br />This configuration change takes effect on the next request to a Web service hosted by the Web application.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-6778459554309010832007-11-20T12:14:00.000-08:002007-11-20T12:33:18.169-08:00Visual Studio 2008 Arrives on TimeOne 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.<br /><br />According to Microsoft's corporate vice president Somasegar (a.k.a "Soma"), Visual Studio 2008 contains over 250 new features.<br /><br />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.<br /><br />The Global Launch of Windows Server 2008, Visual Studio 2008 and SQL Server 2008 will take place on Feb. 27, 2008.<br /><br />You can read the full interview with Soma at <a href="http://www.microsoft.com/presspass/features/2007/nov07/11-19developerqa.mspx">http://www.microsoft.com/presspass/features/2007/nov07/11-19developerqa.mspx</a>George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-76456150041675534212007-11-10T03:48:00.000-08:002007-11-10T04:03:13.223-08:00Simultaneously Calling Several Asynchronous Web Service MethodsIt'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.<br /><br />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.<br /><br />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.<img id="BLOGGER_PHOTO_ID_5131180590204111762" style="DISPLAY: block; FLOAT: left; MARGIN: 10px; CURSOR: hand" alt="" src="http://bp0.blogger.com/_UwePAMT2t7g/RzWdj4V-y5I/AAAAAAAAAQg/OtizRDBlIik/s200/multiple_async_calls_exception_screen_shot.gif" border="0" /><br /><br /><br />Exception has been thrown by the target of an invocation.<br /><br />InnerException<br /><br />"There was an error during asynchronous processing. Unique state object is required for multiple asynchronous simultaneous operations to be outstanding."<br /><br />When I checked the web service methods, they both worked without any problems.<br /><br />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.<br /><br />Look at the code fragment below. m_WSController is the instance of the web service class. Here I call two methods asynchronously:<br /><br />GetPaymentMethodsAsync and GetUserPaymentDetailsAsync. Notice that adding a simple <strong><span style="color:#ff0000;">new object()</span></strong> dummy user state object solves the problem.<br /><code><br />// THIS DOES NOT WORK<br /><br />m_WSController = new MyApp.WebService.Controller();<br /><br />m_WSController.GetUserPaymentDetailsCompleted += new MyApp.WebService.GetUserPaymentDetailsCompletedEventHandler(m_WSController_GetUserPaymentDetailsCompleted);<br />m_WSController.GetPaymentMethodsCompleted += new MyApp.WebService.GetPaymentMethodsCompletedEventHandler(m_WSController_GetPaymentMethodsCompleted);<br /><br />m_WSController.GetPaymentMethodsAsync();<br />m_WSController.GetUserPaymentDetailsAsync(m_SessionId);<br /><br />// THIS WORKS!<br /><br /><br />m_WSController = new MyApp.WebService.Controller();<br /><br />m_WSController.GetUserPaymentDetailsCompleted += new MyApp.WebService.GetUserPaymentDetailsCompletedEventHandler(m_WSController_GetUserPaymentDetailsCompleted);<br />m_WSController.GetPaymentMethodsCompleted += new MyApp.WebService.GetPaymentMethodsCompletedEventHandler(m_WSController_GetPaymentMethodsCompleted);<br /><br />m_WSController.GetPaymentMethodsAsync(<strong><span style="color:#ff0000;">new object()</span></strong>);<br />m_WSController.GetUserPaymentDetailsAsync(m_SessionId);<br /><br /></code><br />Hopefully, this saves you time when getting the above described exception.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-83075753450720121732007-10-30T11:16:00.000-07:002007-10-30T11:21:26.664-07:00Drag-and-Drop Not working When Debugging in Visual Studio Under Windows VistaThere 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).<br /><br />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.<br /><br />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.<br /><br />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.<br /><br />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.<br /><br />Happy programming!<br /><br />More cool posts coming soon.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-20667179308911664022007-10-27T03:53:00.000-07:002007-10-27T04:04:18.566-07:00Connecting SQL Server Management Studio to a Non-standard TCP/IP Port<a href="http://bp1.blogger.com/_UwePAMT2t7g/RyMaZh0OxmI/AAAAAAAAAOw/kyAlZE2cDx0/s1600-h/SQLOnNonStandardPort.gif" target="_blank"><img id="BLOGGER_PHOTO_ID_5125969826754250338" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://bp1.blogger.com/_UwePAMT2t7g/RyMaZh0OxmI/AAAAAAAAAOw/kyAlZE2cDx0/s200/SQLOnNonStandardPort.gif" border="0" /></a>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.<br /><br />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.<br /><br />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.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-23304579519390696442007-10-26T08:39:00.000-07:002007-10-26T09:32:20.872-07:00A Few Words on the Coding StyleWhen developing software, it is important to adopt a good and consistent coding style. It doesn't matter to a computer what coding style you use or if you use any at all. However it does matter to other people reading your code. Even if you work on a project alone and the chances of other people reading your code are pretty slim, it still makes sense to use a clean coding style. Experienced programmers know that after a couple of weeks, even own written code becomes difficult to understand if it is written poorly.<br /><br />When it comes to a coding style, my opinion is that any coding style that makes sense to you is okay as long as you stick to it. Inconsistent coding style is a terrible thing and shall be avoided at all cost.<br /><br />CSharpFriends.com has a <a href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=336">nice article about C# coding</a>. I use the same style with only few exceptions. So, I highly recommend that you read that document. It is a bit lengthy, but will help you quickly grasp my code and the time you will invest in reading it, will pay off quickly.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.comtag:blogger.com,1999:blog-5615146790866724994.post-2018322721393572602007-10-24T10:24:00.000-07:002007-10-24T10:42:15.649-07:00Welcome to ProSoftProgramming.comThank you for visiting ProSoftProgramming.com. As you may have already guessed from the name of the blog, ProSoftProgramming.com will be dedicated to software development. Unlike many other blogs and web sites, our focus will be real-world, complex, enterprise scale applications. I will try to uncover topics not taught in most of the books about computer programming. On ProSoftProgramming.com you won't find such examples as Dog inherits from Animal. Everybody can teach Object-Oriented Programming on simple examples. However, when it comes to large, complex, distributed applications, the task becomes daunting.<br /><br />Search Amazon.com. The world's largest online shop lists thousands of computer programming books but hardly will you find a descent book about building real-world applications. Of course, there are a couple of great books out there, but one cannot cover everything in a book or two. However, on a blog, I'm free to post and deliver material as we progress.<br /><br />To sum up, ProSoftProgramming.com will touch advanced topics of software development and will be most interesting to "intermediate" programmers who are just starting working on large-scale, applications. Our main focus will be Web applications, however many of the concepts will be applicable to non-web applications as well. Microsoft .NET 2.0 will be the primary platform. All of the samples will be in C#.George S.http://www.blogger.com/profile/10755687529493368289noreply@blogger.com