Friday, March 18, 2005

Links : March 18 2005

http://www.codertodeveloper.com/resource_list.htm
http://www.thundermain.com/resources.html
http://blogs.msdn.com/Virtual_PC_Guy

Thursday, March 17, 2005

Developers Must Have Tools

http://www.hanselman.com/blog/content/radiostories/2003/09/09/scottHanselmansUltimateDeveloperAndPowerUsersToolsList.html
http://blog.daemon.com.au/archives/000303.html
http://msdn.microsoft.com/office/default.aspx?pull=/library/en-us/odc_XL2003_ta/html/Office_Excel_Automating_XML_Data_Mapping.asp
http://msdn.microsoft.com/office/default.aspx?pull=/library/en-us/odc_xl2003_ta/html/odc_XMLLists.asp
http://www.theserverside.net/news/thread.tss?thread_id=32106
http://www.mxdu.com/
http://blog.daemon.com.au/archives/000302.html
http://www.saurik.com/net/exemplar/
http://vex.sourceforge.net/

Developer Professionalism

Developer Professionalism

To be paid, is not enough to make one a professional

What is a developers job?
  • To THINK. Coding is a puzzle, puzzles are worked out best by thinking

  • To deliver. On time, on function and on quality

  • To be responsible. Taking personal responsibility

  • To never stop learning. Constant and Never-ending Improvement (CANI)

  • A developer is
  • Punctual. To be on time is to show respect

  • Prepared. To add value to a meeting is to be ready

  • Proactive. Having in mind the consequence and advising on the risk are part of the job, you must drive asking about the requirements, drilling down to the details, raising the risks, getting help!

  • Persistent. No problem is insoluble, balance asking for help with research

  • Precise. In speech and in code exactitude is a hallmark

  • Positive. Decide to be positive but act with caution

  • Prevention Minded. What could happen if this is wrong?

  • A developer is not
  • Overconfident, humility with confidence is the balance

  • Arrogant, confidence is not arrogance

  • Sloppy, neatness is important, clean code is maintainable, safe and correct

  • Hurried, acting with tempo is not hurry, the more important the task the more you should think about the consequences (be like an air traffic controller, become more calm the more the crisis escalates).

  • Late, on-time delivery, on quality, on spec build confidence

  • A cowboy. Process exists to protect the developer and the customer.

  • 7 habits of successful developers
  • Understand that understanding is incremental, requirements are nearly impossible to articulate, so doing a little then showing it to the customer insures that what is delivered is what is needed.

  • Develop incrementally

  • Test continuously with well thought out unit tests peer reviewed by others

  • Have your peers validate your code and design

  • Care about doing the same for others

  • Obey and evangelize standards

  • Leverage tools and go with the tool not against them

  • 7 deadly sins
  • Coding too quickly, time spend in design equals quality in code

  • No or bad unit tests

  • Failing to keep source control in sync

  • Pushing code to production, no developer should ever do this

  • Deployment w/o a rollback

  • Skipping standards you dont like

  • Not honoring peer review e.g. skipping it or ignoring the results

  • The XP Process in a nutshell
  • Get a problem to solve, make it small enough to solve in a day or so

  • Think about what should be tested to determine what done means in terms of functionality and block out the required tests

  • Write a little code and test it, refractor

  • As you develop comment and check for standards

  • When all the tests pass, do a final standards check and then initiate peer review

  • Work with the PM to show and tell it to the customer if not done already

  • When the issues relating to peer review have been dealt with (either fixed or queued up for next time) check in and inform the build team the code is ready for build and QA

  • Repeat until there are no more tasks for the release

  • Start on the next release


  • In XP what does QA do?
  • QA does not exist to test developers code or to find functionality bugs

  • QA role is to assure that the integrated products perform as specified

  • QA Advises on what the required unit tests should be

  • QA judges if the deployment instructions/process is sufficient
  • What are the needed skills to succeed in software project management?.

    Lately, I have been asked to reflect on the last 2 years and come up with a list of skills and resources that have been the most useful in project manangement. Here is my list (so far) annotated with references. The list is quite different the then same list even 1 years ago. truely, the only constant is change. The list reflects the tools that have helped me personally, and may not be a good fit for everyone, these are skills and techniques I have actually used with some success, so if your favorite is missing... Order is not meaningful.

    1. Patience, flexibility, detachment, and a sense of humor. (#1 thing).

    2. Software cost estimation (see my blog entry on COCOMO)

    3. Project mangement tools: red line reviews, MS Project, ...

    4. Software testing using any tool you like + a software test plan against an up to date specification.

    5. Correct staffing. IMHO the ratio of Dev/QA = 1:1 PLUS 1 PM per every 4 devs. Really. The projects that came together the best had these ratios.

    6. Visio. ERD, DFD, System diagrams. Reverse engineering. It rocks.

    7. Powerpoint. Forces crisp clear communications. [See my BLOG]

    8. Visual Studio + SQL Server [duh] I wouldn't build solutions in anything else.

    9. HTML/CSS (really, if you can't code them in a text editor, you do not know them really)

    10. eXtreme programming. It does really make better code. Maybe not for everything, but for critical things.

    11. MS Word with outlining turned on. If you do not use the outliner, learn it, it's worth the effort to learn it. Advice: Outline, content, clean up, format, publish is the correct sequence. [In general, let office be office, don't fight the default formatting , learn to love it. Come be assimilated, resistance is futile.]

    12. A set of requirements or specification that actually captures the business rules kept up to date by devs/PM. Do just enough documentation to get by; as long as spec matches what got built = captured business rules + requirements + deployment/configutration instructions [do not forget these, they are only right if you can demo them, just like a backup only exists once it's been restored successfully].

    13. Tools/toys and gizmos (oh, how did I live without them?): textpad, beyond compare, iconico tools, regulator, WinZip, Snippet compiler, Roxio.

    14. Tunes. Music hath charms to relax the brain. They will pry my music match and dell jukebox out of my numb fingers.

    15. My laptop + wireless connection. I have written great stuff in lots of weird places.

    Thursday, March 10, 2005

    For .NET Interview Questions

    http://www.techinterviews.com/index.php?cat=9
    http://www.techinterviews.com/index.php?cat=9&paged=2
    http://www.techinterviews.com/index.php?p=54
    http://www.techinterviews.com/index.php?p=57
    http://techinterviews.com/index.php?p=66&more=1&c=1
    http://blogs.crsw.com/mark/articles/254.aspx
    http://www.geocities.com/santhosh0123/favorites.html
    http://www.csharphelp.com/archives/archive171.html
    http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20846943.html
    http://msmvps.com/williamryan/archive/2004/10/12/15671.aspx
    http://www.dnzone.com/ShowDetail.asp?NewsId=484

    Tuesday, March 08, 2005

    .NET Web Services using WSE

    .NET Web Services using WSE
    .NET makes creating or using a web service easy, but it's not always exactly as described in the documentation.

    This article covers using the Microsoft Web Services Enhancements (WSE) in Visual C# .NET. I'm assuming you're relatively "au fait" with C# and the .NET framework, and are interested in writing web services.
    There are several ways of writing web services available to programmers using Microsoft's Visual Studio .NET environment, and several programming languages to choose from. Whilst variety may be the spice of life, it does also make it a little difficult to know where best to begin. To compound such problems, the web services scene is changing fast. No sooner have you got your head around using the .NET framework and the web service support available, than yet another set of libraries comes out which purports to "make life easier" in one way or another. I am, of course, referring to the latest
    Web Services Enhancements library shipped by Microsoft.
    Whenever a new class library comes out, I always ask myself whether it's really worth the effort of learning it, or will the library either (a) just add a layer of unnecessary complication to the current development project, or (b) be superseded by another "later and greater" class library in the not too distant future. In order to answer such questions you are immediately landed in a Catch-22 situation, since you have to learn something about the class library before you can decide whether to "go the whole hog" and learn it fully. The purpose of this article is to make you familiar enough with the WSE library that you can answer such questions for yourself.

    Looking at requirements
    One of my current architectural tasks is to look at turning a classic n-tier web-based application that is driven by a browser GUI front-end into a programmatically distributed system. That is, one instance of a server (I like to think of it as a "server atom") can programmatically talk to another server atom somewhere on the Internet (that's correct: not intranet but Internet). I could design our own, private and proprietary data exchange mechanism, operating (probably, but not necessarily) over HTTP. I'm inherently suspicious of anything that's private and proprietary, on the basis that it's almost guaranteed that someone, somewhere will have been confronted with the same task. In any case, it looks like distributed web services are a good bet for a first look at meeting the requirements, but how to communicate between the distributed web services? I could use a fully proprietary design but I dismissed that idea straight away. How about XML RPC after all, I'm looking primarily at an RPC-type environment? Seems fine for connectivity but... the XML documents that I send and receive are once again a proprietary format for XML RPC. The Simple Object Access Protocol (SOAP) addresses this proprietary XML RPC format quite nicely by providing a standard XML format for the messages. So it looks like SOAP is the way to go, at least for the moment. Let's explore this path a little further.
    The kinds of operations I need to support are synchronous and asynchronous calls of remote services, with either type of call possibly returning data either immediately as a result of the call or at some future point.
    I conclude that I need to use SOAP for exposing web services. As the data I return potentially contains sensitive information, I need to look at security of the data transfer. I need to look at the possibility of sending binary data back (e.g. a bcp bulk copy utility query result from a database in native database format).
    This brings me to the heart of this article: Microsoft recently released the WSE library to extend the web service support already provided in .NET. WSE provides me with an implementation of three recently released web service specifications: WS-Security, WS-Attachments and WS-Routing. The question facing me now was whether using WSE would help me in reaching my goal.

    What WSE provides
    Web Services Enhancements, as the "Enhancements" part of the name implies, are extensions to the SOAP specification. That always makes me nervous. The word "extension" implies "non-standard", and non-standard is something I definitely want to avoid. However, the facilities provided by WSE use the SOAP extension model and are also based in some cases on existing Internet draft documents (e.g. WS-Attachments is based on work on the DIME Internet draft). There are other standards out there too. For example, the XACML security specification drafted under the good auspices of OASIS provides a standard for applying a security policy in a web services environment. The parallel to XACML in the Microsoft world is the WS-Policy specification.
    The three WS facilities provided by WSE come under the general auspices of Microsoft's Global XML Web Services Architecture, commonly abbreviated to GXA. It is intended that GXA is an umbrella concept that will use one or more of the WS facilities plugged together by an architect to achieve a final design goal. For example, WS-Routing provides the fundamental services that WS-Security can use to ensure privacy of information. Both WS-Routing and WS-Security are component services of the GXA. WSE is an implementation of the WS-Security, WS-Routing and WS-Attachments specifications. I won't look at how WSE achieves what it does, but will simply focus on how you can use WSE.
    The outline development plan for this article is as follows:
    Write a web service using WSE to expose, say, a factorial calculation
    Write a client to consume that web service
    Re-work (1) and (2) to use security
    Re-work (1) and (2) to send an arbitrary binary attachment, both to and from the web service
    Re-work (1) and (2) to send a binary attachment that is encrypted.

    Getting started
    This section will look at providing a simple web service to expose a factorial calculation and how to configure the server-side web service to use WSE. Once that is done, I will generate a client program to call the web service. The client program will be generated in part by using a proxy-generating tool in Visual Studio .NET. The generated code will need slight modification to use WSE and I'll detail what needs to be done there for the client to use WSE. By the end of this section you should be up and running with a web service and client that use WSE but don't do much with WSE at all. After all that, you'll see in the next section how to start getting WSE involved in helping meet the requirements of a secure web service that can transmit and receive arbitrary length binary data.
    First of all, you'll need to ensure you have IIS up and running. Secondly, you'll need to
    install WSE.
    The particular version of WSE I'm using is WSE 1.0 SP1. While you're at it, you may as well get hold of the
    WSE Settings Tool for Visual Studio .NET.
    Start Visual Studio .NET and create a new Visual C# ASP.NET Web Service project. The name I've given the web service in this article is

    http://localhost/FactorialService
    A short pause ensues while Visual Studio .NET creates a virtual directory called FactorialService on IIS and marks it as an application. The source files are then placed within this virtual directory. Whilst this is fine for development, you may wish to exclude the source files when deploying the web service to your production web server!
    From Solution Explorer, select the Service1.asmx file and rename it to something a little more meaningful. I chose to rename this service to FactorialService by right clicking on the Service1.asmx file and choosing "Properties". In the property inspector, I changed the file name from "Service1.asmx" to "FactorialService.asmx". Now switch to the Class View window in Visual Studio and expand the tree until you can see Service1. Right-click on this and rename it to Factorial.

    Server-Side
    Browsing the C# source, you should find that a commented-out "HelloWorld" method has been provided, prefixed with the [WebMethod] attribute. To modify the web service to provide a factorial function:
    Add two constants for max and min factorial range somewhere in the class

    private const int minFact = 0;
    private const int maxFact = 12;

    Replace the HelloWorld commented-out method with the following method (leaving the [WebMethod] attribute in place)
    public int Calc(int n)
    {
    int factVal = -1;
    // use -1 as out-of-range indicator
    if(n >= minFact && n <= maxFact)
    {
    // factorial by iteration
    factVal = 1;
    // 0! and 1! are both 1 by
    // definition
    for(int factCnt = 2; factCnt
    <= n; ++factCnt)
    {
    factVal *= factCnt;
    }
    }
    return factVal;
    }

    As far as programming goes, that's it! You now have a web service. To hook into WSE, however, you will need to change the application's Web.config file.
    In order for your web service to hook into WSE, you need to add some XML to the Web.config file to tell IIS how to invoke WSE. Select the Web.config file in Solution Explorer and add the required XML entries. This is shown in Figure 1.
    Figure 1
    The element is used with the "type" attribute, which is set to point to WSE by its assembly name. For display purposes, I have had to wrap the "type" attribute so you can see what the value should be. In the actual Web.config file, of course, the type attribute should be one line with no newlines in it. I have omitted the rest of the Web.config file in Figure 1 as it remains as-is.
    You should be able to build the web service now.

    The client
    I'll create a real basic console application in C# to talk to the web service in order to demonstrate that you don't need any heavyweight client code to use a web service. First of all I'll generate a basic client and use Visual Studio .NET tools to generate the required proxy class to talk to the web service. I'll then show how you need to modify the generated proxy file to use WSE. That will complete the basic web service and client configuration.
    In Visual Studio .NET generate a new Visual C# Console Application. I called mine FacClient. You can place the client in the same solution as the web service if you wish, but I chose to keep my client completely separate from the web service project in its own "solution" space. Skeleton code will be generated for you. The first thing you'll need to do is a reference to WSE for your client program. You do this by going to the Solution Explorer and right-clicking over References. From the context menu that opens, select "Add Reference". The resulting dialog is shown in Figure 2, which also shows Microsoft.Web.Services in the list of .NET assemblies.
    Figure 2
    If the assembly does not appear in the list, you will have to use the "Browse" button on the dialog. By default, the DLL is located at:

    %Program Files%\Microsoft
    WSE\v1.0.2312\Microsoft.Web.
    Services.dll

    Once you have located the assembly, click on "Select" then on "OK". In order to use the assembly in your client code you will need to either explicitly reference each instance using the full path name or place the following using directive at the top of your client program: using Microsoft.Web.Services;. You can change the class and file name (as detailed in the section "Server-Side Coding") if you wish, but I chose to leave the class name as Class1 (and filename as Class1.cs) for this simple client.
    Next we need to generate the proxy class to talk to the web service. You do this by right clicking over References in Solution Explorer again - but this time selecting "Add Web Reference" from the context menu, which results in a dialog being displayed. You need to enter the URL that points to the FactorialService.asmx file. Figure 3 shows the URL typed in at the top and the resultant output.
    Figure 3
    Click on the "Add Reference" button at the bottom of the dialog. This adds a proxy class to your project and some more references. Figure 4 shows the "Class View" panel indicating that two proxy classes have been generated in the localhost namespace.
    Figure 4
    The proxy class Factorial is the standard SOAP HTTP proxy class. The other proxy class, and the one we're more interested in, is FactorialWse. The Wse is appended to the name to show that it is using WSE. The difference between the two comes down to the fact that the basic SOAP proxy class derives from the SoapHttpClientProtocol class and the WSE proxy derives from WebServicesClientProtocol, which provides the hooks into WSE.
    Note: the WSE documentation talks about editing the generated proxy class file and changing the inheritance. This documentation point is out of date and you do not need to do this any more. Simply use the "Wse" version of the proxy class.
    In order to use the proxy class add the using directive using FacClient.localhost; somewhere near the top of your client program source and implement Main as follows:

    static void Main(string[] args)
    {
    try
    {
    FactorialWse fs =
    new FactorialWse();
    int val = 6;
    int fac = fs.Calc(val);
    Console.WriteLine(
    "Web service called
    successfully!");
    Console.WriteLine(
    "Factorial of {0} is {1}",
    val, fac);
    }
    catch(Exception e)
    {
    Console.WriteLine(
    "Error with web service: "
    + e.Message);
    }
    }

    You should be able to build and run the client and, all being well, you should find out that the factorial of 6 is 720. Nothing too earth-shattering about that, I agree but what you have done is successfully implemented a web service and client that use WSE albeit at a very basic level. On this foundation, I'm now going to look at using the facilities provided by WSE to see if it can meet my original requirements, which, after all, is the point of the exercise.
    Web services enhancements and WS-specifications
    The WSE .NET library provides an implementation of the WS-Security, WS-Attachments. I'm going to look at WS-Security and WS-Attachments.
    There is no point pursuing the use of WSE if a reasonable degree of data privacy is not achievable using WS-Security. The security mechanism that WS-Security can use is not fixed. For demonstration purposes I will use a simple "shared secret" symmetric encryption process. The major advantage of WS-Security over other security implementations is that WS-Security is implemented on the SOAP packet, whereas other security mechanisms take place at the transport layer (e.g. HTTPS, SSH) and provide a point-to-point encoding. With a distributed web service you don't necessarily know the route a SOAP packet will take, so WS-Security applies security measures at the SOAP packet level rather than the transport level. The WSE documentation contains instructions for building a WSE WS-Security web service that can decrypt a SOAP message and a WSE WS-Security client that can encrypt a SOAP message. I'm going to use the instructions provided in the WSE documentation as a starting point in part because it fulfils one-half of my encryption requirement and in part because the documentation is incorrect in several places and I will show you the correct version in this article. Let's go for building the web service first, then writing the client and generating the proxy class using Visual Studio.NET.
    I'm going to modify the FactorialService and client so that the client can send an encrypted request to the web service to generate the factorial of the encrypted value. Add a reference to Microsoft.Web.Services and System.Security by choosing Add Reference from the context menu on the References node in the Solution Explorer window. You can add both references in one hit in the Add Reference dialog by first choosing "Microsoft.Web.Services" and clicking "Select", followed by choosing "System.Security" and clicking "Select" again. Click on "OK" to complete adding the references. Add the following using directives somewhere near the top of your C# source file:

    using Microsoft.Web.Services;
    using Microsoft.Web.Services.Security;
    using System.Security.Cryptography;
    using System.Security.
    Cryptography.Xml;
    using System.Security.Permissions;

    Notice that the WSE documentation in Point 9.b is missing the using System.Security.Permissions; directive.
    In order to decrypt the incoming message, you need to provide a DecryptionKeyProvider in the form of a class. WSE will use your class to decrypt the SOAP message at the point of reception and then pass the decrypted message to your web service. As far as your main web service is concerned, it knows nothing about the encryption of the call it is all handled by WSE and your own custom class. Point 10 in the WSE documentation describes the method of adding a class to be used for DecryptionKeyProvider, but it's unfortunately out-of-date in stating that your class needs to implement the IDecryptionKeyProvider interface. This is no longer true your class should inherit from a WSE base class called DecryptionKeyProvider. Given that the example in the WSE documentation calls its own class DecryptionKeyProvider, if you also inherit from a class called DecryptionKeyProvider then you have a circular inheritance loop and the code will no longer compile. In summary, you need to change the inheritance and also call the class something different to the one in the WSE documentation. I called my class DecKeyProv and declared it as:

    public class DecKeyProv :
    DecryptionKeyProvider

    The security attributes for this class are the same as in the WSE documentation, although the WSE documentation version will not compile due, firstly, to the missing using directive (dealt with above), and secondly in part due to the fact that the method as given does not compile!
    If you do try to compile the method GetDecryptionKey as given in the WSE documentation you will get an error to the effect of "not all control paths return a value". The easiest way of fixing this is to add return null; just after the close of the foreach loop as the last statement in the method that will fix the error. Now on to the warning: a warning is issued about your GetDecryptionKey method hiding the base class GetDecryptionKey method. What you need is to override the base class implementation so the declaration for your GetDecryptionKey method becomes:

    public override DecryptionKey
    GetDecryptionKey(...).

    This is what an outline of the class and method should look like:
    public class DecKeyProv :
    DecryptionKeyProvider
    {
    public override
    DecryptionKey
    GetDecryptionKey(
    string algorithmUri,
    KeyInfo keyInfo)
    {
    // body as per WSE document
    // (plus corrections)
    // or exactly as in the code
    // sample for this article
    }
    }

    The DecKeyProv class can be added to the FactorialService namespace. For ease of writing, I placed the class in the same source file as the main web service, although you could place it in a separate file if you wish.
    XML web service life just wouldn't be the same without editing an XML file somewhere or other, so I'll look next at what you need to do to the Web.Config file to get the WS-Security functionality up and running.
    The first thing you need to configure is the server-side to use the WS-Security implementation in WSE, so it's back to the Web.config file. I'm working on the basis that you've already added the standard WSE blurb as detailed in "Server-Side Configuration" above. A couple of things need to be in place in the Web.config file to cater for security. The first is to add a that gives a name to the WSE library (we'll call it microsoft.web.services as per the WSE documentation). The second step involves using the microsoft.web.services section you've just defined to pull in your security class for decryption. You can add this directly beneath (not inside!) the element. Both these steps are shown in Figure 5.
    Figure 5
    The "type" attribute of the section tag (in ) is exactly the same as the "type" attribute as shown in Figure 1. I didn't re-format it here for display purposes to emphasise the fact that the type attribute should be on one line in the Web.config file.
    All the pieces are now in place and you should be able to build the web service successfully.

    Client Security
    Using the earlier client, add a reference to System.Security via Solution Explorer. Add the following using directives to the top of the source file:
    using Microsoft.Web.Services.Security;
    using System.Web.Services.Protocols;
    using System.Security.Cryptography;
    using System.Security.
    Cryptography.Xml;

    The procedure for encrypting your request follows a simple pattern:
    Generate an EncryptionKey object
    Modify the SOAP proxy class's requestContext to use the EncryptionKey
    Call the service
    The WSE documentation for "Encrypting a SOAP message Using a Shared Secret" gives an implementation of a method called GetEncryptionKey, which uses TripleDES as the encryption algorithm. We'll run with this version, so all you need do is add the GetEncryptionKey method to your client code. I made a slight modification to the visibility of the GetEncryptionKey that is made private in the WSE documentation. I turned it into a public static method to facilitate ease of use from my console application's Main method.
    The complete procedure for the client console app is reproduced here to show how the above three steps are executed. The code forms the body of Main.

    // proxy class
    FactorialWse fs = new FactorialWse();

    // encryption key
    EncryptionKey key =
    Class1.GetEncryptionKey();

    // modifying requestContext to encrypt
    SoapContext requestContext =
    fs.RequestSoapContext;
    EncryptedData enc =
    new EncryptedData(key);
    requestContext.Security.Elements.Add(
    enc);
    requestContext.Timestamp.Ttl = 30000;
    //30 secs, avoid replay hacks

    // actually calling the web service
    int val = 6;
    int fac = fs.Calc(val);
    Console.WriteLine("Factorial of {0}
    is {1}", val, fac);

    WS-Attachments
    I need to send arbitrary binary data, and I may need to send it encrypted too, as it may contain personal or commercially sensitive information. WSE supports arbitrary transfer of binary attachments using DIME.
    To enable the web service to send an attachment using DIME, add the following using directive to FactorialService.asmx: using Microsoft.Web.Services.Dime;
    To actually send a binary attachment all you need do is add a DimeAttachment object to the Attachments collection of the SOAP response context. The DimeAttachment object wraps the binary data you wish to send. A code sample illustrates sending a GIF image file (roughly taken from the WSE documentation):

    // 1. Get response context
    SoapContext ctx =
    HttpSoapContext.ResponseContext;

    // 2. Create the dime attachment
    // object, wrapping the image file
    DimeAttachment att =
    new DimeAttachment(
    "image/gif", // MIME type
    TypeFormatEnum.MediaType,
    // media type enum
    @"c:\myimage.gif");
    // filename of image

    // 3. Add the DimeAttachment object
    // to the response
    ctx.Attachments.Add(att);

    That's it. In terms of our factorial web service, you can add a method that will return some binary data, call it, say, GetBinData. For the sake of consistency with the WSE documentation, let's stick to sending a binary image file for now. Add a public web services method to the factorial service like so:
    [WebMethod]
    public void GetBinData()
    {
    // body as above for sending GIF
    // image via DIME
    }

    To obtain some test data, just copy any GIF image you have locally to the root directory of the C drive and rename it to myimage.gif so that the web service can locate it. The client needs to be able to get the binary attachment from the SOAP message, a process that turns out to be relatively simple. The client looks at the Attachments collection of the ResponseSoapContext object exposed from the client's WSE proxy class. The WSE documentation shows a simple C# client application displaying the image in a picture window. The WSE sample application meets all the requirements of proving that WSE's WS-Attachments is working fine, so I won't produce a separate client for this article.
    Summary
    This article has looked at a readily available implementation of the two web services standards (WS-Security and WS-Attachments), and has hopefully given you a starting point from which you can expand your web service implementations on the .NET platform using WSE.

    Passing Methods As Parameters in .NET/C#

    Passing Methods As Parameters: Delegates to the Answer
    On the ASPAdvice C# list someone had asked, "Is it was possible to pass a method as a parameter."
    The answer of course is yes, by using delegates. The follow is a rather simple example.//First, define a delegate with the signature you wish
    //to pass as a parameter
    public delegate int ComputeTwoNumbers(int x, int y);
    //Simple class with 4 methods which match our delegate signature
    public class ComplexMathmatics
    {
    public int Multiply(int x, int y)
    {
    return x * y;
    }
    public int Divide(int x, int y)
    {
    return x/y;
    }
    public int Subtract(int x, int y)
    {
    return x - y;
    }
    public int Add(int x, int y)
    {
    return x + y;
    }
    }
    //Our example class which takes a method (via our delegate) as a parameter.
    public class Calculator
    {
    public int Compute(int x, int y, ComputeTwoNumbers c2n)
    {
    return c2n(x,y);
    }
    }
    //Our example in action
    //Delcare a new instance of our super complex math class :)
    public ComplexMathmatics math = new ComplexMathmatics();
    //create our "method" parameters
    ComputeTwoNumbers multiply = new ComputeTwoNumbers (math.Multiply);
    ComputeTwoNumbers divide = new ComputeTwoNumbers (math.Divide);
    ComputeTwoNumbers subtract = new ComputeTwoNumbers (math.Subtract);
    ComputeTwoNumbers add = new ComputeTwoNumbers (math.Add);
    //lets get ready to work it :)
    Calculator calc = new Calculator ();
    int x = 4;
    int y = 10;
    int m = calc.Compute(x,y,multiply);
    int d = calc.Compute(x,y,divide);
    int s = calc.Compute(x,y,subtract);
    int a = calc.Compute(x,y,add);

    Friday, March 04, 2005

    Debugging JavaScript in VS.NET for ASP.NET application

    The following tip will explain how you can setup your JavaScript code to be debugged in VS.NET.
    1. Create a file named something.js and then add all your JavaScript functions to this file.
    2. Add the js file to your ASP.NET project.
    3. Then in every ASP.NET page that will call one of those functions add the following line to the HEAD section of the page. script lanaguage=“javascript“ src=“something.js“
    4. Before running the solution in debug mode set a break point in the .js file where you would like it to stop.

    Now run the solution in debug mode and VS.NET will break at that point every time the application executes that code.

    Thursday, March 03, 2005

    .NET/C#/ASP.NET Interview Questions

    Here's a list of some questions I use when interviewing .Net developers.

    Here's a list of some questions I use when interviewing .Net developers. It is not exhaustive, but should give the interviewer an idea of the basic level of expertise an individual has. If the interview is for a senior developer, these questions should be followed by more in-depth questions that relate to the specific projects (Web Services, SOA, XML, etc).
    ASP.Net

    Q. Explain the differences between Server-side and Client-side code? A. Server-side code executes on the server. Client-side code executes in the context of the clients' browser.
    Q. What are some ways to manage state in an ASP.Net application? A. Session objects, Application objects, ViewState, cookies, hidden form fields.
    Q. What does the "EnableViewState" property do? Why would I want it on or off? A. It allows page objects to save their state in a Base64 encoded string in the page HTML. One should only have it enabled when needed because it adds to the page size and can get fairly large for complex pages with many controls. (It takes longer to download the page).
    Q. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other? A. Server.Transfer transfers excution directly to another page. Response.Redirect sends a response to the client and directs the client (the browser) to load the new page (it causes a roundtrip). If you don't need to execute code on the client, Transfer is more efficient.
    Q. How can I maintain Session state in a Web Farm or Web Garden? A. Use a State Server or SQL Server to store the session state.
    Q. What base class do all Web Forms inherit from? A. The Page class.
    Q. What does WSDL stand for? What does it do? A.(Web Services Description Language). It describes the interfaces and other information of a web service.
    Q. Which WebForm Validator control would you use if you needed to make sure the values in two different WebForm controls matched? A. CompareValidator Control
    Q. What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control? A. You must set the DataSource property and call the DataBind method.
    C# Questions
    Q. Can you explain what inheritance is and an example of when you might use it? A. Inheritance allows us to extend the functionality of a base class. It is an "Is a" type of relationship rather than a "Uses" type of relationship (a dalmation IS A dog which IS A canine which IS A mammal - dalmations inherist from dog which inherits from canine which inherits from mammal). All child classes retain the properties and methods of their parent classes but may override them. When you want to inherit (use the functionality of) another class. Base Class Employee. A Manager class could be derived from the Employee base class.
    Q. Does C# support multiple-inheritance? A. No, use interfaces instead.
    Q. Can you prevent your class from being inherited by another class? A. Yes. The keyword “sealed” will prevent the class from being inherited.
    Q. What does the keyword “virtual” declare for a method or property? A. The method or property can be overridden.
    Q. What's the top .NET class that everything is derived from? A. System.Object.
    Q. What does it mean that a String is immutable? A. Strings cannot be altered. When you alter a string (by adding to it for example), you are actually creating a new string.
    Q. If I have to alter a string many times, such as mutliple concatenations, what class should I use? A. StringBuilder. It is not immutable and is very efficient.
    Q. In a Try - Catch - Finally block, will the finally block execute if an exception has not occurred? If an Exception has occurred? A. Yes and yes.
    Q. Whats MSIL, and why should developers need an appreciation of it, if at all? A. MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.
    Q. Explain the three tier or n-Tier model. A. Presentation (UI), business (logic and underlying code) and data (from storage or other sources).
    Q. What is SOA? A. Service Oriented Architecture. In SOA you create an abstract layer that your applications use to access various "services" and can aggregate the services. These services could be databases, web services, message queues or other sources. The Service Layer provides a way to access these services that the applications do not need to know how the access is done. For example, to get a full customer record, I might need to get data from a SGL Server database, a web service and a message queue. The Service layer hides this from the calling application. All the application knows is that it asked for a full customer record. It doesn't know what system or systems it came from or how it was retrieved.
    Q. What is the role of the DataReader class in ADO.NET connections? A. It returns a forward-only, read-only view of data from the data source when the command is executed.
    Q. Is XML case-sensitive? A. Yes.
    Q. What is the CLR? A. Common Language Runtime
    Q. Can you explain some differences between an ADO.NET Dataset and an ADO Recordset? (Or describe some features of a Dataset).A. A DataSet can represent an entire relational database in memory, complete with tables, relations, and views. A DataSet is designed to work without any continuing connection to the original data source. Data in a DataSet is bulk-loaded, rather than being loaded on demand. There's no concept of cursor types in a DataSet. DataSets have no current record pointer You can use For Each loops to move through the data. You can store many edits in a DataSet, and write them to the original data source in a single operation. Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources
    Q. Name some of the Microsoft Application Blocks. Have you used any? Which ones? A. Examples:Exception Management Logging Data Access User Interface Caching Application Block for .NET Asynchronous Invocation Application Block for .NET Configuration Management Application Block for .NET (there are others) We use Exception and Data Access

    Biztalk Webcasts

    Support Web Casts
    The following is a list of previously recorded Support Web Casts for BizTalk Server 2004. Upcoming web casts can be found here.
    BizTalk 2004 Overview & VS.NET Integrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG&pw=35DKTQ
    Setup & Installationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-1&pw=35DKTQ
    Comparison & Migrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-2&pw=35DKTQ
    XML Editorhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-3&pw=35DKTQ
    XML Mapperhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-4&pw=35DKTQ
    Orchestrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-5&pw=35DKTQ
    Deploymenthttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-6&pw=35DKTQ
    Content Based Routinghttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-7&pw=35DKTQ
    Pipeline & Custom Componentshttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-8&pw=35DKTQ
    BizTalk Message Queuing (MSMQ/T)http://www.placeware.com/cc/microsoft/view?id=6DWNGR-16&pw=494ZRK
    Web Services and Orchestrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-10&pw=35DKTQ
    Rules Composerhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-11&pw=35DKTQ
    Advanced Orchestration, Part 1http://www.placeware.com/cc/microsoft/view?id=JUPBAG-12&pw=35DKTQ
    Health and Activity Tracking (HAT) & Debugginghttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-13&pw=35DKTQ
    Business Activity Services (BAS)http://www.placeware.com/cc/microsoft/view?id=JUPBAG-14&pw=35DKTQ
    Advanced Orchestration, Part 2http://www.placeware.com/cc/microsoft/view?id=JUPBAG-15&pw=35DKTQ
    Human Workflow Services (HWS)http://www.placeware.com/cc/microsoft/view?id=JUPBAG-16&pw=35DKTQ
    InfoPath/BizTalk 2004 Integrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-17&pw=35DKTQ
    BizTalk Adapter Frameworkhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-18&pw=35DKTQ
    Business Activity Monitoring (BAM)http://www.placeware.com/cc/microsoft/view?id=JUPBAG-19&pw=35DKTQ
    BizTalk Explorer & Administrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-20&pw=35DKTQ
    Enterprise Single Sign-On (SSO)http://www.placeware.com/cc/microsoft/view?id=JUPBAG-21&pw=35DKTQ
    EDI Covast Adapterhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-22&pw=35DKTQ
    SQL Adapterhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-23&pw=35DKTQ
    Performance, Stress & Scalabilityhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-24&pw=35DKTQ
    SAP Adapter - Bryan McCutchanhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-25&pw=35DKTQ
    Migrating from BizTalk 2002 to 2004http://www.placeware.com/cc/microsoft/view?id=JUPBAG-26&pw=35DKTQ
    MQSeries Adapterhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-27&pw=35DKTQ
    SharePoint Adapterhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-28&pw=35DKTQ
    Advanced Orchestrationhttp://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032253626
    HIPAA 3.0 Acceleratorhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-29&pw=35DKTQ
    Advanced Dev - Crypto Pipeline, Submit Direct, Orchestrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-31&pw=35DKTQ
    Trading Partner Management & FTP Adapterhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-30&pw=35DKTQ
    SWIFT Acceleratorhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-32&pw=35DKTQ
    RosettaNet Acceleratorhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-33&pw=35DKTQ
    HL7 Acceleratorhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-34&pw=35DKTQ
    BizTalk Configuration and Administrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-35&pw=35DKTQ
    Orchestration Drilldown: Transactions, Exceptions and Compensationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-36&pw=35DKTQ
    BizTalk Adapter Wizardhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-37&pw=35DKTQ
    HIS Integration with BizTalkhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-38&pw=35DKTQ
    Advanced Mappinghttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-39&pw=35DKTQ
    BizTalk PowerToyshttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-40&pw=35DKTQ
    BizTalk 2004 Administration Management Toolhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-41&pw=35DKTQ
    Microsoft BizTalk Adapter for WSE 2.0 Technical Overviewhttp://www.placeware.com/cc/microsoft/view?id=WSE2.0&pw=WSE2.0
    UK SDC BizTalk 2004 Documenter v.2.0http://www.placeware.com/cc/microsoft/view?id=JUPBAG-42&pw=35DKTQ
    BAM Drilldownhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-43&pw=35DKTQ
    Building Adapters From Scratch Using VB.NEThttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-44&pw=35DKTQ
    BizTalk 2004 Adapter for MSMQ (NAIAD)http://www.placeware.com/cc/microsoft/view?id=JUPBAG-45&pw=35DKTQ
    BizTalk Native Adapter & Orchestration Tips & Trickshttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-46&pw=35DKTQ
    Trading Partner Management (TPM) & Business Activity Services (BAS)http://www.placeware.com/cc/microsoft/view?id=JUPBAG-47&pw=35DKTQ
    WRQ Verastream BizTalk 2004 Screen Scraping Adapter for Legacy Integrationhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-48&pw=35DKTQ
    Clearway Workflow Suite and Microsoft BizTalkhttp://www.placeware.com/cc/microsoft/view?id=JUPBAG-49&pw=35DKTQ
    ODBC Adapter for BizTalk Server 2004http://www.placeware.com/cc/microsoft/view?id=BTSBAG-54&pw=35DKTQ