Thursday, September 30, 2004

VJs Tip Of The Day - September 30th 2004

Generating Proxies for WebServices

If you have created web services and wish to generate proxy classes for your webservices then there is a tool in VS.Net called "WSDL"... This tool will take the location of your .asmx file as a parameter and will dynamically generate proxy class for your web service.
There are various switches used by this class like for eg \l:vb will create the proxy class in vb; \o:C:\MyProxyClass.vb will create the proxy class at a particular location. There are many other options check out MSDN for further information. Click here

PS: I have got infected by new kind of psychological disorder... When I am working I look forward to having fun... When I am having fun I look forward to work... During weekdays I wait for weekends, during weekends I wait for Monday to come and rush back to work... I know such situations are called "Circular referencing" or "Cyclic dependencies" technically but I wonder what is psychological term... Pointers would be appreciated!!

Wednesday, September 29, 2004

VJs Tip Of The Day - September 29th 2004

Build Vs Rebuild in VS.Net

A very basic but a less know question for today... What is the difference between Build and Rebuild solution in VS.Net or why at all we have two...
Well the difference is that Build solution will build only those projects which are changed since the last build... It will not get the changes of the updated embedded resource files...
Rebuild solution will cause everything to be rebuilt no matter whether it was changed or not...

If you are making small projects the differences would not matter much but for large builds these are really useful...
There are advanced differences though but these are something which all should know...

PS: If you wish to add few of your discoveries shoot me an email and I will update folks with tomorrow's tip...

PS:Swapnil B has added to the list and made it explicit that Rebuild will bydefault update your refrences too...

Tuesday, September 28, 2004

VJs Tip Of The Day - September 28th 2004

Activator.CreateInstance

Activator is a class in System namespace... This class is one of the most widely used class to create instances at runtime, of types locally or remotely defined... Usually it returns back an object or an objecthandle... There are lots of overloads of this method and in local scenarios mostly take System.Type() as one of the parameter... Its certain overloads also take typename as string and return back an object handle... This objecthandle then needs to be unwrapped to get back the object... The overload which returns objecthandle is mostly used in remoting...

CreateInstance is a static member of the class and so can be accessed directly without object creation...

PS: Abhishek, Microsoft India MVP lead has helped us get the below information:

Announcing Security Guidance Hands-On Labs Online
Microsoft Learning is pleased to announce the free, worldwide availability of Hands-On Labs 2811, Applying Microsoft Security Guidance, at http://www.microsoftelearning.com/security/.
This offering consists of four 90-minute labs that allow students to apply information and guidance to improve security in a network based on Microsoft Windows. These labs have been enormously successful at live events since their original release in April 2004, with over 12,000 deliveries through Certified Partners for Learning Solutions (CPLS). In addition, these labs have been offered at conferences and events worldwide, including TechEd US, TechEd Europe (highest-scoring labs).
Lab 1: Managing Security Updates

Lab 2: Implementing Server Security

Lab 3: Implementing Client Security for Windows 2000 and Windows XP

Lab 4: Implementing Application Security

Customers can now take these labs for free at home or in the office by registering at http://www.microsoftelearning.com/security/. The labs are conducted using real hardware in a safe online environment built on Microsoft Virtual Server technology. These are the first free hands-on labs online offered by Microsoft Learning and these will be followed by additional free labs on Windows XP Service Pack 2.

Monday, September 27, 2004

VJs Tip Of The Day - September 27th 2004

SoapInclude Attribute

In case of webservice programming you can allow SoapInclude Attribute on your webmethod to make sure that the specific type gets passed by... You use this attribute on your webmethod when in normal circumstances that type would not get passed...
For instance, if you have a class inheriting for a base class and a member is declared of the type base class and later instantiated as derieved, then the derieved class will not get passed across in that scenario on your webmethod you would apply this attribute...

Look at the example below...

<WebMethod(), SoapInclude(GetType(Circle)), XmlInclude(GetType(Circle))> _
Public Function ReturnSomething(ByVal key As String) As Shape
If (key = "Circle") Then
Dim circl As Shape = New Circle()
circl.area = 2
Return circl
End If
End Function

<Serializable()> _
Public Class Shape
Public area As Double
End Class

<Serializable()> _
Public Class Circle
Inherits Shape
Public radius As Double
End Class

Thursday, September 23, 2004

VJs Tip Of The Day - September 23rd 2004

Asynchronous Programming in WebServices

Callback functions are the way to implement Asynchrounous programming in Webservices... We will get into details of this topic sometime but now just an overview...
A client calls the Begin method on the server object and passes a reference to the callback method... The asynchrounous method on the server object finishes execution and gives a call back to the method on the client object... This method in client object now causes the call to End method on the server object.... The End Method then returns the result to the client...
Well why would you do such a thing??... The simple reason can be when your server side execution is really going to take long and you do not want to wait for all that processing to happen...

PS: I just remembered a saying from a wise man, thought I would remind you all of that too...
"If Everything is under control... Then you are not moving fast enough..."

Wednesday, September 22, 2004

VJs Tip Of The Day - September 22nd 2004

Application Domanis

Application Domains are the boundaries within which applications run... Application domains provide an isolated environment to applications, the kindof isolation level that is very similar to process isolation levels, though what is worth nothing is that a process can have multiple application domains within itself... An application running in one app domain cannot directly access code running under other app domain...

Monday, September 20, 2004

VJs Tip Of The Day - September 20th 2004

App Config File not being picked up

Some times you would have done nearly everything right in the windows application but still on trying to access configuration file you would get back null or nothing... Well the problem might be the name that you have used for the config file...

You should know that for a windows based application to pick up app.config file following should be taken care of...
1.) The app.config name should match your assembly name... i.e. if you have myapp.exe then the config file name should be myapp.exe.config...
2.) Also you should know that the config file is picked up for the main or the application which is the starting point... So your app.config file should be attached to that...

PS: There is a small correction to the above tip... Thanks to Darya, an old colleague of mine for pointing it out... I have corrected the blog if anyone can tell me what I corrected then a virtual candy from me to him/her... :-)


PS: I counted that close to 37 people asked me "How are you?" today... Out of these only 7-8 actually waited for me to respond, rest all just walked by... I wondered why such formalities when no one really cares to know, but then I thought - This is atleast a good way of proving our kids that "Man is a social being..."

Thursday, September 16, 2004

VJs Tip Of The Day - September 17th 2004

Callback functions

Callback functions are powerful tools and we should know how to use them... In general a callback function is a reference to a method that you pass to another method... When the second method calls the referenced method , it actually calls back to the first method... This might be a confusing terminology but a code snippet from MSDN will probably help make it clearer...

using System;
using System.Runtime.InteropServices;

public delegate bool CallBack(int hwnd, int lParam);

public class EnumReportApp {

[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);

public static void Main()
{
CallBack myCallBack = new CallBack(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
}

public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}

Here is the link for you to explore more.... Click Here


PS: I have coined a new term called "Developer's Superstition"... I suffer from this problem often - When code does not seem to behave the way I want it to, knowingly/unknowingly I try things which I know will not work, which I know are technically impossible but still I do just to make myself feel good that I have left no stones unturned... I wonder whether you guys also do such thing... A classic example would be trying to call GC.Collect() method when a StreamReader is not releazing a file even after calling close()...{usually its some other process holding the reference...:-)} I wonder has MS Technologies made me superstitious or is this same everywhere... :-)

VJs Tip Of The Day - September 16th 2004

Xcopy Deployment

Xcopy command is used to easily copy all the files of a .Net application to a target installation directory... For applications that do not require any further registration Xcopy is command is the simplest way to distribute your .Net applications...

Do note that Xcopy command does not copy the hidden and system files... Also note that Xcopy creates files with the archive attribute set, whether or not this attribute was set in the source file...If you have a disk that contains files in subdirectories and you want to copy it to a disk that has a different format, you should use the Xcopy command instead of Diskcopy. Since the Diskcopy command copies disks track by track, it requires that your source and destination disks have the same format. Xcopy has no such requirement. In general, use Xcopy unless you need a complete disk image copy or you wish to copy the system files.

PS: All I ever needed to Know, Most of what I needed to know about how to live, And what to do and how to be, I learnt in Kindergarten. Wisdom was not at the top of the Graduate school mountain, But there in the sandbox at Nursery school. These are the things I learned: Share everything. Play fair. Don’t hit people. Put things back where you found them. Clean up your own mess. Don’t take things that aren’t yours. Say sorry when you hurt somebody. ......Be aware of wonder. Remember the little seed in the plastic cup. The roots go down and the plant goes up and Nobody really knows how or why, but we are all like that....
These are the wonderful words of Robert Fulgam... Read his book "All I Need To Know, I Learnt in Kindergarten" and do remember- "Technology should not overwhelm you"...

Wednesday, September 15, 2004

VJs Tip Of The Day - September 15th 2004

Resource File Generator Tool

Resource file generator tool is used to convert resource file in the form of .txt or .resx files to common language runtime binary .resources files... These files can be compiled into satellite assemblies..

This utility can do conversions in other directions too and uses following classes to do the conversions
ResourceReader Class
ResourceWriter Class
ResXResourceReader Class
ResXResourceWriter Class

The exe name for the tool is ResGen.exe... If you search MSDN with the keyword you will find ample information...

PS: I was wondering when would people start using MSDN to search MSDN and not Google... I am trying to develop this good habit... :-)

Tuesday, September 14, 2004

VJs Tip Of The Day - September 14th 2004

Quick MultiThreading
This is some real quick good info for specific scenarios... If you are writing some workflow logic of yours and in-between you realize that you want to perform some tasks which would be time consuming but actually are also apart from your actual business logic and so you would not want your business logic to waste on performance by waiting for those tasks to complete... Some of the examples of such tasks would be printing, cleaning back-end, doing logging or tracing functionality etc...
Well this is when the System.Threading.ThreadPool class comes real handy... There is a static method called QueueUserWorkItem... You can call this method with the method that you want to execute Asynchronously... The Threadpool will use the first available thread to process your request... Now your main business logic does not need to wait for this function to finish...
Now this function can as well give a call back but then it depends upon your requirements...
Read more about it on MSDN... Click Here...
PS: This tip is a result of my discussions with Matt, a colleague of mine... We often discuss interesting technical stuff in our "Leisure At Work" (LAW can never be illegal right!!)

Note: Caution on multithreading... You should know that if different threads are gonna use the same resource then multithreading might cause performance hits as well... Thanks Kathleen for reminding...

Monday, September 13, 2004

VJs Tip Of The Day - September 13th 2004

ToolTip in Windows

Well if you have been doing Web development for a long time in .Net now, if you switch to windows it would pretty much possible for you to search for the standard ToolTip property for all the controls and guess what you won't find it... :-) Windows UI is much more richer than web and so the windows controls try to leverage that... For this reason there is a special ToolTip control which is provided to you in the windows environment which you can associate with any of your controls...
Now what are some of its advantages the code below will tell you:

ToolTip vjsTip = new ToolTip();
vjsTip .InitialDelay = 1500;
vjsTip .ReshowDelay = 1000;
vjsTip .SetToolTip(this.txtZipCode, "You need to provide a zip code only if you are in US or Canada");

Similarly you also have GetToolTip() method... Well so go ahead and try explore more on the ToolTip control...

PS: Hope you all are doing fine!!...How did it feel when a forcible mail did not drop into your mailbox for so many days??... Good!!..Bad!!...Well, after giving you a small break, I am back again to bug you, make you take your pill daily... But if you do not like the pills then drop me a mail I will try that they don't reach you... Otherwise, the second season has begun... :-)

Monday, September 06, 2004

Very Limited Access To Internet

Hi All,
I have very limited access to internet as of now and I will be getting a new connection set up at my home only by Sept 11th 2004... I have my entire mailing list as well all my work on my laptop/CDs... Only after my internet connection is up I would be able to update any further posts or send tips...
Please bear with me till then...
best wishes,
Vishal Joshi
If You Think YOU CAN... You Can...

Tuesday, August 31, 2004

VJs Tip Of The Day - August 31st 2004

COM Callable Wrapper(CCW) - In simple terms -CCW is the special wrapper created over your .Net classes so that they appear as COM objects to other COM components... If your .Net application needs to be called by other COM components you need to make sure that CCW is created over your .Net classes...

Runtime Callable Wrapper (RCW) - In simple terms - RCW is a special wrapper created over COM components so that they appear as .Net components to other .Net components... If your .Net components call other COM components then you need to make sure that RCW is created over the COM components that your application calls...

PS: I will be shifting to Milwaukee, WI tomorrow... Till I get my new home set up, I might not be having any access to internet so probably would not be able to send in Tips for a while... I apologize in advance for the same and will try to get back to grove ASAP...

Monday, August 30, 2004

VJs Tip Of The Day - August 30th 2004

Maintaining State Across ASP.Net Pages - Continued 4

Due to the weekend you might have lost touch... In that case do browse through the previous tips on the blog site... The current mail is in continuation of previous tips...

There is a possibility of InvalidCastException, which may come in case of using properties with Server.Transfer... If you think for a while you can very easily conclude the possible causes...
1.) SecondPage is called from a page other than the FirstPage
2.) SecondPage is directly loaded
3.) SecondPage is called from any other page using response.redirect

In such a scenario do make sure that you catch this exception and ignore it...

PS: You know blogspot has provided search facility for the blogs... So now if you want to search some specific tip in my blog you can use that search facility and you will get the tip right over there... :-)

Friday, August 27, 2004

VJs Tip Of The Day - August 27th 2004

Maintaining State Across ASP.Net Pages - Continued 3

Yesterday we discussed on NOT having second parameter to be true in Server.Transer() method while transferring data of first page to next page using properties... Visit the previous tips to follow up...
Now the answer to "WHY" not true... Well, I was trying that out yesterday and I got an exception message:
"The View State is invalid for this page and might be corrupted"...

On exploring more I discovered that: It is that "EnableViewStateMac"* property of the page(which we discussed few days back)is set to true by default... If this property is true ASP.Net makes a check to find out if the viewstate was modified or not when the page was posted from the client... Now as in case of Server.Transfer's second parameter being true what happens is that all the form variables (including viewstate) of the first page is preserved and sent to second page... Here due to EnableViewStateMac being true a check is made by ASP.Net but now as you are no more in first page so it is but obvious that this check will fail... And as in case of properties option without setting second parameter of Server.Transfer as true also the values are transferred so you can as well pass it to be false...
As such you can also make "EnableViewStateMac" as false but that would not be a good idea from security perspective...

*MAC stands for Message Authentication Check

PS: You know Sudhakar Sadasivuni, a fellow MVP has helped to get all our MVP blogs at one place at the site http://www.mvpblog.com... I bet you will find loads of information here so do visit it when you find time...

Thursday, August 26, 2004

VJs Tip Of The Day - August 26th 2004

Maintaining State Across ASP.Net Pages - Continued 2

Hi Folks,
I apologize for abruptly stopping the tips... I was not having any access to internet for the last few days... I am shifting to Milwaukee, Wisconsin to join in as a .Net System Architect in an MNC... I will remain busy during this transition but will ensure that I do not display this abrupt behavior again... The tips of Aug 23rd, 24th and 25th are up there on my blog site(Click Here) The current tip is in continuation of the previous tips so please do visit the site and catch up before you move ahead...


4.) Using Properties with Server.Transfer: Make your first page in such a way that you expose the required values in next page as properties in the first page... Then use Server.Transfer to go to the next page(keep the second parameter as false here, WHY SO WE WILL TALK TOMORROW)... Now in the next page using context handler you can get all the properties of the first page...

I am not writing the first page code as it is just simply adding values into properties and calling Server.Transfer and I believe you all know how to do that...

CODE SNIPPET

NextPage Code:

if(Context.Handler != null)
{
string strInternalVariableOfNextPage;
FirstPage objFirstPage = new FirstPage();
objFirstPage = (FirstPage)Context.Handler;
//Note that SomeValue is a public property of First Page
strInternalVariableOfNextPage = objFirstPage.SomeValue;
}
PS: I like receiving mails that blast me on not sending the tips... This keeps me motivated so thanks to all those who wrote in those mails...

Wednesday, August 25, 2004

VJs Tip Of The Day - August 25th 2004

Maintaining State Across ASP.Net Pages - Continued 1

3.) Using HttpContext/RequestParams with Server.Transfer: We discussed adding to session yesterday, similarly you can add to HttpContext as well and this eliminates the cleaning code required in the next page like the way it is required in Session... There are other advantages too...

If you use Server.Transfer then all your control values are automatically transferred to the next page you do not have to add anything to the context explicitly here rather just access the values in the coming page... The code example will show this more clearly...

If you have certain values other than the above mentioned then you have to do certain special operations to explicitly add them in the first page and retrieve them in the second...

CODE SNIPPET

FirstPage Code:
//These are the special values being added to context
//we will retrieve them in the next page
context.Items.Add("specialVariableName", "specialVariableValue");
//We set the second parameter of Server.Transfer to True this will help
//sending certain values automatically
Server.Transfer("NextPage.aspx", True);


NextPage Code:
string strValueOfFirstPageTextBox;
string strSpeciallyAddedValue;
//Use Request.Params to get values of the standard variables
//which get automatically transferred
strValueOfFirstPageTextBox = Request.Params.Get("firstPageTextBox")
//Use HttpContext to get the values specially added
strSpeciallyAddedValue = context.Items("specialVariableName")

Tuesday, August 24, 2004

VJs Tip Of The Day - August 24th 2004

Maintaining State Across ASP.Net Pages

We will talk about two standard methods of maintaining state across ASP.Net pages today... The more sophisticated methods will be discussed from tomorrow onwards...

1) Using QueryString : You can pass values of one page to another page using Query strings... This is an old ASP custom but for security reason not always recomended in ASP.Net

2) Using Session : You can also pass values of one page to another by storing them in session... Use of session is pretty simple and we have discussed that earlier as well (Click Here)... But do understand the fact that Session variables are to store user specific information which is unique to each user and not each page... Also do note that if you forget to clean the session variables in the next page you might land up increasing the session size like anything effecting performance of your application...

Monday, August 23, 2004

VJs Tip Of The Day - August 23rd 2004

Steps to Enable Automatic Transactions in .Net

We have discussed all these steps earlier but now we will club them together to see how you go about doing it....
1. Add TransactionAttribute to your class
2. Derieve your class from ServicedComponents class
3. Give strong name to your assembly
4. Register your class for COM+ services using Regsvcs.exe