August 2003 - Posts
Asynchronous Web Service calls are a beautiful thing. Web services I was executing from a console app I mentioned earlier were timing out and Asynchronous WS calls got me back in the pink. I sketched out the basic framework in using an asynchronous call below. I won't provide a play-by-play because there are good references elsewhere.
private static void CoolWebService()
{
Appname.Component oComponent = new Appname.Component();
Appname.Server.Class ws = new Appname.Server.Class();
AsyncCallback cb = new AsyncCallback(THISClass.CoolWebServiceCallback);
IAsyncResult ar = ws.BeginCoolWebService(cb, ws);
while (ar.IsCompleted == false)
{
// wait
}
}
public static void CoolWebServiceCallback(IAsyncResult ar)
{
Appname.Server.Class ws = (Appname.Server.Class) ar.AsyncState;
ws.EndCoolWebService(ar);
}
I've been wrestling with relaying .NET STMP messages beyond our local domain since around 3:00 this afternoon. It's now around 5:30. I know, it's a Friday, but darn it, when something doesn't work on one of my servers--whether that particular something is in use or not (and this happens to be not in use)--it bugs me and has to be fixed.
We all have CDO email procs and sometimes need to send to non-domain addresses. My classic ASP CDO procs worked fine, and am quite certain my .NET 1.0 CDO proces did, but not .NET 1.1. I knew it had something to do with .NET security, and tried impersonation, changing the username to SYSTEM in the machine.config, adding ASPNET to the SMTP admin group, etc. Then I found the Golden Google Egg below.
SmtpMail.SmtpServer = ""; // I had it pointing to the exchange server...
It makes perfect sense now. You must use LOCALHOST as your smtpserver and let IT do the forwarding for you.
Ahhh, yes. Now I can relax and enjoy my weekend.
Thank you Charles Fineblum!
From: Charles Fineblum (charle1@comcast.net)
Subject: Re: SMTP error: Could not access 'CDO.Message' object
Newsgroups: microsoft.public.dotnet.languages.csharp
Date: 2003-08-18 11:39:20 PST
Hi Chad:
"You need to use localhost and set the forwarding of your local SMTP server to your main mail router server"
By setting SmtpMail.SmtpServer = "", it should use local smtp server. How do I set forwarding to main mail server? I don't see this setting in SMTP props. I also tried adding the ASP.net account in security tab of SMTP prop, but still same error.
Thanks,
Charlie
I broke-out the freetextbox.dll control from Scott Watermasysk's .TEXT framework for another project of mine. (Is my understanding correct that this control was written on Linux? It's a very sweet control!) In testing I kept getting an error message "Potentially harmful code was posted ...." or something to that effect. I could NOT figure it out. dotnet.newsgroups via Google to the rescue once again:
Adding <B><PAGES validateRequest="false" />in the web.config did the trick.
Update: Great suggestion from G. Andrew Duthie as a better security practice: turning off Page Validation at the PAGE level and not in the web.config along with filtering out everything except what you want to accept. Also good references from Victor Garcia Aprea on validation. See comments.
I am currently a serious student of the Scott Watermasysk School of Rocking Web Application Design. I am working with his .TEXT framework and customizing it to meet specific needs of my company. (More on that when the customization is complete.) But as someone said before me, studying Scott's code is an excellent lesson in Best Practices. I heartily agree.
| One of the things that struck me was how Scott breaks out the application to multiple project classes. I was thinking about how to keep my web application .DLL from becoming too large (I personally don't like to exceed 200K in a web app's DLL.) While engaged in this thought process I look at Scotts project layout in VS.NET (at right.) I've seen this before when I studied the Angry Coder's eZine framework, heck, a year-and-a-half ago, but the light didn't turn on like it did when I looked at the .Text solution window. I would in the past have a /components subdirectory and try to adhere to putting my business and data layers there, but breaking out the various components into separate project classes (and thus DLLs) seems to be exactly where I want to be going in my web app design.
|
 |
It is also quite cool that VS.NET handles the references and compilation of the classes which comprise the solution. I used to think the references had to be deleted and re-referenced each time the project referenced was changed. Wrong!
Its the first time I say this and I'm sure it will not be the last time: "THANKS, SCOTT!"
We don't get many MSDN sessions up here in Burlington, Vermont, so when one is available, I go!
The two sessions were led by Joe Stagner and were on 1) Deploying Smart Client Applications, and 2) Office 2003 and Visual Studio 2003. I just wanted to say that I enjoyed the heck out of these sessions and really like Joe's style.
Here are my notes on Deploying Smart Clients and on Office 2003 and VS.NET 2003, taken on my Dell Axim PocketPC and portable keyboard.
I have one thing to say about Office 2003 and VS.NET 2003: According to the presentation, the first release of Office 2003 only provides .NET managed code support for Word and Excel. Why can't we have .NET managed code support for OUTLOOK as well? I mean, my God. My users use Outlook as much as they use Word or Excel. Advanced communication or email handling capabilities through enhanced .NET Outlook apps would be as beneficial to my company as Smart tags and Smart Docs. Sometimes it just burns my crawl where the line is drawn on new product features.
I remember the errors I used to get while writing VB6 COM (which I thought at one time was the coolest technology in the world--that and rolling back a transaction with maybe sending something to MSMQ--who could want anything more???) But the error messages were less than helpful. "Reference object null" or some lame message to that affect was one I saw a lot.
Today I was reminded what a change VS.NET has made in describing compile and runtime errors. I was compiling a web app which was referencing a couple of other class projects and received this:
c:\Documents and Settings\whoever\My Documents\Visual Studio Projects\proj\proj.Data\bin\Debug\proj.Utils.dll Referenced class 'proj.Utils.Cache' has base class or interface 'System.Web.UI.Page' defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web'.
Sweeeet! I knew how to fix that! And it sure beat the heck out of "Reference object null."
We moved to VS.NET 1.1 last week and all has gone pretty smoothly. I did discover the other day that certain web controls no longer served up the data which originated from various remote server shares. Once I knew the problem the fix was obvious: it was time to modify the default machine.config file installed with the 1.1 Framework (.../Framework/v1.1.4322/CONFIG/machine.config.)
Changing USERNAME="machine" to USERNAME="SYSTEM" in the PROCESSMODEL section did the trick. Perhaps .NET should be set to Username="SYSTEM" by default?
Update: Many thanks to Jim Blizzard and G. Andrew Duthie (again) for straightening me out on this and for showing me that it is definitely not a best practice. I'll be changing the machine.config username back to “machine” default and using impersonation in the web.config. See Comments.
In one of my projects I use a series of asynchronous web service calls from a console app running as a scheduled job to create XML data files from a Sharepoint Server document library through the Microsoft OLEDB Provider for Internet Publishing (MSDAIPP).
The XML data files become an intelligent middle data layer and are integrated with SQL Server data to provide some pretty cool functionality. I need to put an article together on it... Anyway, the console app which generates the XML data files spits out a log file with times for completing the various XML data file creation tasks. Like so:
Log Entry : 8:21:34 AM 8/27/2003 : 22 seconds : Created Folder Workfile
Log Entry : 8:23:48 AM 8/27/2003 : 133 seconds : Created All Files Gold
Log Entry : 8:24:16 AM 8/27/2003 : 28 seconds : Created Search File
Log Entry : 8:24:31 AM 8/27/2003 : 14 seconds : Created PID File
Log Entry : 8:24:51 AM 8/27/2003 : 20 seconds : Created PID Project Folder File
The second totals just weren't correct and I let the error persist for a week or so while I attended to more important tasks. The log file was just for my personal monitoring needs, after all. When I had a minute I went back to see what I was doing wrong. The original code was:
System.TimeSpan TotalTime = System.DateTime.Now - StartTime;
Double secs = TotalTime.Seconds;
Log(secs.ToString(), "Created Folder Workfile");
After a little digging into the TimeSpan structure, I read that .Seconds was "the second component of this instance, between 0 and 59" where .TotalSeconds was "the total number of seconds represented by this instance." So
Double secs = TotalTime.TotalSeconds;
yielded the correct second count, along with some ToString()... formatting to remove the fractional digits, providing a clean and correct output.
I realize this is an inconsequential incident, but its one of those cool finds that reinforces the wealth of class members and properties available in VS.NET with a little digging.
I have been a blog consumer but not a producer for the last few weeks. Blogs have been in my life for about 6 months, I guess, and I've been blogging for about 4 months. Lately I've been getting weighed down trying to cover my personal OPML blogscape when I should instead be coding.
So I've been writing less and skimming posts like a champ. The subject of blog overload has been eloquently addressed by several before me, but I've learned most keenly since the arrival of .NET that my attention has to be more focused on my immediate programming or educational needs than ever before. And in conjunction with a very narrow subject focus, if I'm not writing code, I'm not learning. End of story. The old saying "learn by doing" has never been more applicable.
So anyway, just wanted to mention that its easy for a developer to lose focus on priorities, and that lack of focus may even possibly include spending too much time with the Scobleizer. (btw, only 4 posts today Mr. Scoble? What's up with that????)
I watched a rather disturbing NOW with Bill Moyers episode on PBS tonight addressing the topic of exporting service-oriented jobs along with DEVELOPER jobs to places like India. One figure mentioned was an annual salary comparison of an average $66,000 for a US developer compared to something like $10,000 for a developer in India. The real world interviews with technical people out of work because of their jobs being exported really hit home. Also shown was an excerpt from a memo by a "Senior Microsoft VP" which said something to the effect "look for areas to move offshore now!"
Because it is perceived as a dirty secret by corporations who move these jobs offshore, the piece discussed how larger corps are contracting outsourcers to take over a function but whose real intention is to eliminate those jobs and replace them with workers offshore.
Below is the listing from tvguide.com. The show is being re-broadcast tomorrow and Sunday.
| 9:00 PM |
Channel 6 WETK |
Friday, 29 | |
NOW with Bill Moyers 60 min.
Topics include the “exporting” of white-collar U.S. jobs in such fields as technology and financial services to such countries as India. | |
More Posts
Next page »