Sunday, January 27, 2008

Wednesday, January 23, 2008

.net interview questions

Preparing for .net interview to face soon? or planning to take net interview? Find Scott Hanselman's post on .net interview questions here -
http://www.hanselman.com/blog/WhatGreatNETDevelopersOughtToKnowMoreNETInterviewQuestions.aspx
HL - Dipesh

Thursday, January 17, 2008

Debug .net source code through Visual Studio 2008

With the news of open source code for Visual Studio 2008 now available i was wondering how do you achieve this and i ran into this quite detailed article by Shawn here - http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx

As of date .net assemblies that are currently available as open source or for symbol/source loading where developers can actually step into VS .net source code are:-
Mscorlib.DLL
System.DLL
System.Data.DLL
System.Drawing.DLL
System.Web.DLL
System.Web.Extensions.DLL
System.Windows.Forms.DLL
System.XML.DLL
WPF (UIAutomation*.dll, System.Windows.DLL, System.Printing.DLL, System.Speech.DLL, WindowsBase.DLL, WindowsFormsIntegration.DLL, Presentation*.dll, some others)
Microsoft.VisualBasic.DLL

I believe more will follow! happy debugging... Regards - Dipesh

Wednesday, January 16, 2008

HTTP 401 Unauthorized error while inserting/updating through CRM web service

If you are experiencing 401 error - "The request failed with HTTP status 401: Unauthorized" while inserting/updating a record in CRM database through CRM web service .create or .update method even when you can access the CRM web service/meta web service through browser (IE) then you may want to probably check your "manage network password" of your windows login account. Control Panel -> Users -> User name -> Manage network password and add the server IP (where CRM web service is hosted) with correct credentials if required or if you changed your network password then try updaing your password in here as well. Stop the current process run and try running/accessing the CRM web service insert/update and it should work fine. HTH, - Dipesh

Tuesday, January 15, 2008

Code assessment and code metrics through Visual Studio 2008 and third party tools!

If you are planning to assess your old application code and generate code statistics (lines of code, complexity, etc.) then here are some tools that may help:

nDepend - http://www.ndepend.com/Features.aspx

Reflector has code metrics - http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=CodeMetrics

Visual Studio 2008 can generate code metrics too:
http://blogs.msdn.com/fxcop/archive/2007/10/03/new-for-visual-studio-2008-code-metrics.aspx

Also, find CCFinderX that bring us another point of view in code analysis for .net and non .net code - http://www.ccfinder.net/ccfinderx.html

CRM 3.0 rollup 2 download and fixes

Tool that would allow you to rename schema name can be found as Mscrmrenameattributes.exe along with CRM 3.0 rollup update install. Unfortunately, i am not sure if Microsoft provides this as a seperate one.

Key issues that are fixed in Update Rollup 2 for Microsoft Dynamics CRM 3.0

918990 (http://support.microsoft.com/kb/918990/) You experience timeouts or slow performance after you change a security role or after you import a customization file in Microsoft Dynamics CRM 3.0

920135 (http://support.microsoft.com/kb/920135/) Error message when you try to import a customization into Microsoft Dynamics CRM 3.0: "The selected customization file does not conform to the required customization file schema"

920859 (http://support.microsoft.com/kb/920859/) Error message when you send an e-mail message in Microsoft Dynamics CRM 3.0: "You do not have enough privileges to access the Microsoft CRM Object or perform the requested operation"

921065 (http://support.microsoft.com/kb/921065/) Internet Information Services stops responding on a Microsoft Dynamics CRM 3.0 server

921235 (http://support.microsoft.com/kb/921235/) You experience timeouts or slow performance when you reassign records from one user to another user in Microsoft Dynamics CRM 3.0

923281 (http://support.microsoft.com/kb/923281/) The client stops responding when you try to go offline or to run the "Synchronize Outlook with CRM" function in Microsoft Dynamics CRM client for Outlook

925437 (http://support.microsoft.com/kb/925437/) Error message when you send an e-mail message from the Microsoft Dynamics CRM 3.0 Web client: "Insufficient Permissions"

925505 (http://support.microsoft.com/kb/925505/) Microsoft Outlook stops responding when you click a command button on the Microsoft Dynamics CRM toolbar

925874 (http://support.microsoft.com/kb/925874/) An update for the 2007 daylight saving time changes is available for Microsoft Dynamics CRM 3.0 and for the Microsoft Dynamics CRM 3.0 client for Outlook

928272 (http://support.microsoft.com/kb/928272/) Outlook exits unexpectedly when you click "Go Offline" in the Microsoft Dynamics CRM laptop client for Outlook

929488 (http://support.microsoft.com/kb/929488/) Error message when you attach a .docx file to a record in Microsoft Dynamics CRM 3.0: "File Upload Failure"

931270 (http://support.microsoft.com/kb/931270/) Error message when you use the Microsoft Dynamics CRM client for Microsoft Office Outlook: "Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience"

932984 (http://support.microsoft.com/kb/932984/) How to make the 2007 daylight saving time changes by using the Update Time Zones Wizard for Microsoft Dynamics CRM 3.0

for details visit - http://support.microsoft.com/default.aspx?kbid=927751

Download rollup 2 update for MS CRM 3.0 server here -

* CRM3.0-KB927751-Server-ENU.exe package - http://www.microsoft.com/downloads/details.aspx?FamilyId=81674DA5-FFEF-492A-A7B1-7E1F1951B05F

Download CRM 3.0 client for Microsoft Office Outlook here -

* CRM3.0-KB927751-Client-ENU.exe package - http://www.microsoft.com/downloads/details.aspx?FamilyId=81674DA5-FFEF-492A-A7B1-7E1F1951B05F

Secure FTP connect through .net + other tools...

If you want to SFTP (secure connect) through .net here's the code that helps you achieve that using CuteFTPPro as below. If you want to compare with other options available in the market follow the link below. HTH,

public void SecureFTPConnect()
{
.....
// Open the SFTP connection
Sftp = new CuteFTPPro.TEConnectionClass();
Sftp.Host = ServerName;
Sftp.Protocol = Protocol;
Sftp.Port = PortNumber;
Sftp.Login = UserName;
Sftp.Password = Password;
Sftp.MaxConnections = 1;
Sftp.Retries = 0;
Sftp.TransferType = "ASCII";

//Connect to SFTP location
Sftp.Connect();
}

Check few more SFTP (SSH File Transfer Protocol) components for .NET (C#, VB.NET) here - http://www.eldos.com/sbb/sftpcompare.php

Thanks - DJ

Thursday, January 10, 2008

Calling web services from remote machines easy way: Test environment

If you are faced with the web service error while invoking the service from remote machine, by default, it would display the message "The test form is only available for requests from the local machine."

Add this piece of section in your web.config to enable your web service to be invoked from remote machines,
Add the following settings to the Web.Config file of the Web Service -

(XML start << and >> signs are not visible...dont know how to do that with this blogger editor!)
system.web
webservices
protocols
add name="HttpGet"
add name="HttpPost"
/protocols
/webservices>
/SYSTEM.WEB

This would enable the Web service to be able to be invoked from remote machine. This setting would only be useful in development / testing scenarios and it is advisable to remove /comment the above section when releasing for production, due to security reasons.
HTH - DJ

Wednesday, January 09, 2008

Download Visual Studio 2008 (complete software or Virtual machine)

If you are a MSDN subscriber, you can download your VS 2008 copy from the MSDN subscription site - http://msdn2.microsoft.com/subscriptions

If you are a non-MSDN subscriber, you can download a 90-day free trial edition of Visual Studio 2008 Team Suite here -
90-Day Trial Downloads
Visual Studio 2008 Professional Edition (smaller in size)
Visual Studio Team System 2008 Team Suite
Visual Studio Team System 2008 Team Foundation Server
Visual Studio Team System 2008 Test Load Agent

If you want to use the free Visual Studio 2008 Express editions (which are much smaller and totally free), you can download them here.

If you want to just install the .NET Framework 3.5 runtime, you can download it here.

If you are looking for Virtual Machine (VPC) with Visual Studio 2008 Installed for You then check here -

Visual Studio Team System 2008 Team Suite with Visual Studio Team System 2008 Team Foundation Server
Visual Studio Team System 2008 Team Foundation Server with Team Explorer
To use these virtual machines, you must have either Virtual PC 2007 or Virtual Server 2005 R2 SP1.

If you want free MSDN library it is avaialble for download here - http://go.microsoft.com/?linkid=7947400

To help you jump start with new features with VS 2008 you can download free Visual Studio ebook here - http://go.microsoft.com/?linkid=8010142

Keep watching this blog if you are interested in exploring new features on VS 2008 apart from this ebook. Happy exploring! Cheers - Dipesh

Tuesday, January 08, 2008

Generate code from WSDL/XSD from Visual Studio 2005

In my search of doing my job faster in the development of web services i found this pretty helpful tool: WSCF - Web Services Contract First. This helps us generating .net code (C#, vb.net) from WSDL, XSD and so on. You can generate proxy classes for .net/java or any other client and also .net web service - server side code all from Visual Studio 2005.

You can find the latest version here- http://www.thinktecture.com/media/7478/wscf0.7.zip
You can find the walkthrough document here - http://www.thinktecture.com/resourcearchive/tools-and-software/wscf/wscf-walkthrough

Thanks - Dipesh

Friday, January 04, 2008

Improve web service performance

Mike has posted a nice article that helps one achieve faster web service performance by compressing SOAP. Read here - http://www.dotnetjunkies.com/Article/46630AE2-1C79-4D5F-827E-6C2857FF1D23.dcik

You may want to peek at Microsoft's article as well - http://msdn2.microsoft.com/en-us/library/s25h0swd.aspx

Hope that helps. - DJ

How to compress/uncompress string in .net before passing it over the network?

If you want to compress string before passing it over the network to save bandwidth or uncompress it back here is the code for the same. It usese freeware NZIPLIB library. You can download the source code and compiled assembly from this site. Download now!

using System;
using NZlib.GZip;
using NZlib.Compression;
using NZlib.Streams;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Xml;
namespace zipper
{
public class MyClass
{
public static string Compress(string uncompressedString)
{
byte[] bytData = System.Text.Encoding.UTF8.GetBytes(uncompressedString);
MemoryStream ms = new MemoryStream();
Stream s = new DeflaterOutputStream(ms);
s.Write(bytData, 0, bytData.Length);
s.Close();
byte[] compressedData = (byte[])ms.ToArray();
return System.Convert.ToBase64String(compressedData, 0, _
compressedData.Length);
}

public static string DeCompress(string compressedString)
{
string uncompressedString="";
int totalLength = 0;
byte[] bytInput = System.Convert.FromBase64String(compressedString);;
byte[] writeData = new byte[4096];
Stream s2 = new InflaterInputStream(new MemoryStream(bytInput));
while (true)
{
int size = s2.Read(writeData, 0, writeData.Length);
if (size > 0)
{
totalLength += size;
uncompressedString+=System.Text.Encoding.UTF8.GetString(writeData, _
0, size);
}
else
{
break;
}
}
s2.Close();
return uncompressedString;
}
}
}

Wednesday, January 02, 2008

XSDObjectGen - nested schema (imports) error with XSD.exe tool

If you read my previous post http://archdipesh.blogspot.com/2008/01/xml-xsdexe-usage-tips.html you may be good if you are using a simple XSD file (no nesting). But if i have multiple XSD files and they are all nested then there is a problem! Using XSD.exe tool doesn't help and fails for nested schema files.

It seems XSD.exe doesn’t seem to recognize element when generating code file...and it spits out the error ... "Class generation failed, cannot recognize root element". If you are facing the same error remove imports element from the XSD just include the namespace and try specifying multiple XSD file names from the command line while executing xsd.exe tool.

OR ... sweet way would be to look at XSDObjectGen tool. This is pretty exhaustive and can handle imports/mutiple xsd files easily. (though one level down). This code can then be used as a class exposed by web services.
Download Sample Code generator from here - http://www.microsoft.com/downloads/details.aspx?familyid=89e6b1e5-f66c-4a4d-933b-46222bb01eb0&displaylang=en

Saves lot of time and pain for sure! HTH, Thanks - Dipesh

XML, XSD.exe usage tips

Here are few quick tips that can help you understand and start with XML basics...

Questions - (preferably in this sequence)
How do you generate XSD ?
You need to have a valid XML file for which you want to have a schema generated ( XSD)
If you have VS .net you can just open the xml file into VS.net and then under XML menu you should see "Create Schema" option that should generate an .xsd file for you!

How do you create classes from an XSD schema?
You can create .net (C#, VB, J#) source code from the xsd using XSD tool (command line) along with MS .net framework.
http://samples.gotdotnet.com/quickstart/howto/doc/xmlserialization/xsdtocls.aspx

How do you convert (deserialize) XML into an object that you can read through .net code?
AND
How do you write out an XML file (serialize) from an object through .net code?

http://samples.gotdotnet.com/quickstart/howto/doc/xmlserialization/rwobjfromxml.aspx

Thats simple ...is it? Thanks - Dipesh

How do i authenticate web service requests before invoking web methods ?

How do i pass user name, password when calling web services ? or
How do i authenticate the web service request before invoking web methods ?

There are several ways to do this and one of the most easiest way is to pass user name, password as input parameters to web method called. but na, that is not a good way to implement as this information is at the periphery of the core business functionality of the web service exposed. Hence keeping this out makes more sense.

Another way to control anonymous access can be achieved through IIS (web server) settings. Just uncheck the anonymous access or limit the IPs that can hit your web services or validate it against your windows account group... but again you may want to implement partial anonymous access! Few web methods can be accessed by everyone, few have restricted access.

In that case, better way to do this is to pass this information into SOAP header (SOAP web services communicate through SOAP messages - which include SOAP envelope (inc. namespace and root element), SOAP Header (this is optional) and SOAP body (contains web method, input parameters and response result)

Working with SOAP Headers in order to have a Web service accept a SOAP header we need to perform the following three tasks:
1> Define a SOAP header class in the Web service project

public class AuthenticationHeader : SoapHeader
{
public string Username;
public string Password;
}

2> Add a public member variable of the SOAP header class created in step (1) to the Web service class

[WebService(Namespace=
http://www.comp.com/yournamespace )]
public class MyWebService : System.Web.Services.WebService
{
public AuthenticationHeader AuthHeader;
... The Web service's methods would be defined down here ...
}

3> Add the SoapHeader attribute to the Web method(s) that need to be able to programmatically access the value of the header

Once we perform these three steps at the Web service's end, our next task is to configure the client so that it can invoke a Web service method and pass along data for the appropriate SOAP header(s). The first step, as we've discussed in earlier installments of this article series, is to create a proxy class on the client. This will auto-generate the SOAP header class defined in the Web service project and will add a public property to the proxy class through which an instance of the SOAP header can be affixed to outgoing messages.

To actually pass along a populated SOAP header when calling a Web method the client needs to first create an instance of the proxy's SOAP header class, populate its values, and then assign this header class instance to the appropriate proxy class property. Finally, calling one of the Web service's methods will invoke the method, passing along the SOAP header.

[WebMethod(), SoapHeader("AuthHeader")]
public string GetMessage()
{
// Only allow valid user/password to access this secret message...
if (AuthHeader.Username == "user" && AuthHeader.Password == "password")
return "This is the secret message!!!";
else
return "YOU ARE NOT AUTHORIZED TO SEE THIS MESSAGE!";
}

In order to send a SOAP header to the Web service method, the client should do the following:
1> Create an instance of the proxy class,
2> Create an instance of the SOAP header class and populate its values,
3> Affix the SOAP header to the proxy class by assigning the SOAP header class instance created in step (2) to the proxy class's AuthHeaderValue property, and, finally
4> Call the Web service method

The following code illustrates these four steps. The GetMessage() Web method is invoked from the client passing along a username/password pair of scott and password.

// step 1, create the proxy class
localhost.MyWebService proxy = new localhost.MyWebService();
// step 2, create and populate the header class
localhost.AuthenticationHeader authInfo = new localhost.AuthenticationHeader();
authInfo.Username = "user";
authInfo.Password = "password";
// step 3, affix the SOAP header to the proxy
proxy.AuthHeaderValue = authInfo;
// step 4, call the method
string result = proxy.GetMessage();
The value returned from GetMessage() will contain the appropriate message, based on the username/password sent via the SOAP header.

Conclusion - If you want to know more or learn real sweet about the whole web services or SOAP basics and details visit
Scott Mitchell's article on http://aspnet.4guysfromrolla.com/articles/123103-1.aspx. He has written 11 part series about .net web services. Hope that helps! Thanks - Dipesh

XML Serialization: what can be XML serialized and what cannot be ?

Few points that you would like to know about XML serialization that may be also important if you are planning to face an interview soon :P)

Realize that XML serialization:
1> XML serialization can only be applied to classes that contain a public default (parameterless) constructor. If you create a class in the Web service that does not have a public default constructor, the Web service will still compile, but when attempting to generate the proxy class on the client's end you'll receive an error message.

2> Read-only class properties are NOT serialized. That is, if a property in the class has only a get accessor, and not a set accessor as well, the property will not be serialized.

3> ONLY public properties and fields are serialized. Private properties are not serialized.

4> To serialize a strongly-typed collection of objects, have the class derived from System.Collections.CollectionBase adding an Add() method and an indexer.
Alternatively you can send an array of the specified type.

On the last point, consider the case where you want a Web service method to accept a set of custom class instances. For example, imagine you wanted to build a Web method that accepted a number of instances of type CreditCardInfo. One option is to have the method accept an array of type CreditCardInfo, like so:

[WebMethod()]
public void FooBar(CreditCardInfo [] collectionOfCCInfos)
{
...
}
Another option is to create a strongly-typed collection class derived from System.Collections.CollectionBase. You'd then pass in an instance of this strongly-typed collection class. For example, you'd first create the class:

public class CreditCardInfoCollection : System.Collections.CollectionBase
{
public void Add(CreditCardInfo cc)
{
this.InnerList.Add(cc);
}

public CreditCardInfo this[int index]
{
get { return (CreditCardInfo) this.InnerList[index]; }
set { this.InnerList[index] = value; }
}
}
And then you'd have the Web service method accept an input of this strongly-typed collection class:
[WebMethod()]
public void FooBar(CreditCardInfoCollection collectionOfCCInfos)
{
...
}

See this article for more details on web services and XML related basics...
http://aspnet.4guysfromrolla.com/articles/121703-1.aspx


btw, Happy New Year 2008 :)
Happy programming - DJ