Saturday, April 9, 2011

Key Learnings Abdul Azeem Khan

Problem:
While uploading a file by converting file content into array of bytes and sending it to server side via WCF, generates following exception.

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:***. The InnerException message was ‘There was an error deserializing the object of type ****. The maximum array length quota (16384) has been exceeded while reading XML data

Impact:
You will not be able to download or upload file bigger than 1 megabyte.

Solution:
Change the web.config or the app.config file to the following settings.


<bindings>
        <basicHttpBinding>
          <binding
                   maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="0:50:0" openTimeout="0:50:0" receiveTimeout="0:50:0" sendTimeout="0:50:0"
                   >
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2097152"  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </binding>

          </basicHttpBinding>
</bindings>
After this recompile the file and run you application again

Monday, April 4, 2011

Key Learnings Abdul Azeem Khan

Problem: 
While working with ASP.NET ajax toolkit, you get the following exception

" Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure “AjaxControlToolkit.Properties.Resources.resources” was correctly embedded or linked into assembly “AjaxControlToolkit” at compile time, or that all the satellite assemblies required are loadable and fully signed."

Impact:
This will break your website, and it will render is non funcational

Solution:

If you are working with asp.net ajax toolkit extension, The latest incarnation (3.6.097 as of this writing) of the asp.net Ajax Control Toolkit needs to be setup using its script manager and not the standard asp.net Script Manager.

So one way to avoid the above issues is to drag the ToolkitScriptManager (found in the control toolkit) onto the Form tag and then use any other Ajax Controls. Here is an example of it using the TabContainer

<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server"/>
<div>
    <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1">
        <asp:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            <ContentTemplate><p>Hello</p></ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
        <ContentTemplate><p>Hello2</p></ContentTemplate>
     </asp:TabPanel>
    </asp:TabContainer>
</div>
</form>
 
Hope it help!!!

Saturday, April 2, 2011

Key Learnings Abdul Azeem Khan

Problem:
Intellisense fails to fire up for skin files in any asp.net application

Impact:
This will make it cumbersome to code style rules for standard asp.net server controls and can waste a lot of your time and make your code error prone

Solution:
1. Go to Tools->Options menu.
2. Pick Text Editor -> File Extesion from a tree at the left part of Options dialog.
3. Type skin in Extesion text box.
4. Select User Control Editor from Editor dropdown.
5. Click Add and then Ok to close dialog and re-open your skin files.


 

Wednesday, March 30, 2011

Key Learnings Abdul Azeem Khan

Problem:  
Incorrect Syntax Near “.” during DataAdapter.Fill

Impact:
Your program hangs and you are not able to access the data from the database


Solution:
If you have a SQL statement such as this:
            string statement = "Select title, addDateTime, keyword_id, keyword, lang_id" +
"FROM tableX"; 


the problem is caused due to the lack of space after "lang_id", to solve the problem just put in an extra space, so it would be "lang_id ".
 

Tuesday, March 29, 2011

Key Learnings Abdul Azeem Khan

Problem: 
 java.lang.IllegalAccessException: Class com.sun.xml.ws.fault.SOAPFaultBuilder can not access a member of class Services.CustomException with modifiers "public"

Impact :
When working with custom Exceptions in Web Services, and when you throw them as faults, your Web Service will stall and be no longer funcational.

Solution:

1) Always make a separate package to store your custom exception.
2) Derive your custom exception from Exception class
3) You have to include getFaultInfo() within your custom exception class and this is the key
4) In your @WebMethod include the throws clause and specify the name of your custom exception.

If you follow the steps listed above, there should be no error mentioned above. 

Monday, March 28, 2011

KeyLearnings for Abdul Azeem Khan

Prolem:  

getting an "IllegalStateException" when using the RequestDispatcher? 
1)java.lang.IllegalStateException: Header already sent 
2)java.lang.IllegalStateException: Cannot forward as Output Stream or Writer has already been obtained

Impact

Slows down your servlet communication, and at times can make your application behave intermittently.


Solution:


Make sure you only have one RequestDispatcher.forward("url") coded in your servlet and make sure it is always placed at the very end.


Also there is an interesting tip adapted from:


http://www.jguru.com/faq/view.jsp?EID=501393


Which states that:


If you want your response-writers to be modular (one object to build the nav bar, one object to build the banner ad, one object to build the body, one object to build the page footer, etc.), you have two choices:
  1. use JavaBeans or Java method calls to build up the HTML in the response, or
  2. use RequestDispatcher.include() to bring in content from many little servlets from inside a master response-builder servlet.


Tuesday, March 22, 2011

Key Learning Abdul Azeem Khan

Problem :
Target "compile-test-single" does not exist in the project "FileUploadExample". It is used from target "profile-test-single".

Impact:
In Netbeans you can no longer run any Enterpise, Web or Client application. A pretty serious issue

Solution:

The problem occurs when you accidentally hit a profiler button. To resolve the issue

Click on Profile > Attach Profiler > And Select External Application

Make sure to select External Application and no Internal Application

Monday, March 21, 2011

KeyLearnings for Abdul Azeem Khan

Problem:
Do you get any of the following WCF related communication exceptions
  •  CommunicationException"
  • "CommunicationObjectAbortedException"  
  • "IOException" and "SocketException"
     
Impact:
This can halt communication between client and server using one-way, request/response or two-way communication modes.


Solution:
You need to configure the "Namespace Reservation" setting on your computer using netsh tool developed by microsoft.

For Windows Xp use the following code:
step1: httpcfg set urlacl /u {http://URL:Port/ | https://URL:Port/} /aACL
step2: httpcfg.exe set urlacl /u http://myhost:8000/ /a "O:AOG:DAD (A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"


For Windows Vista and Windows 7 use the following code:
netsh http add urlacl url=http://+:80/MyUri user=DOMAIN\user

Tuesday, February 15, 2011

Using .NET Async Pattern to Invoke WCF service

Tip:
When Invoking WCF services there comes a time when you need to give up procedural synchronous ways of doing things and use the arbitrary asynchronous ways to do things. This post will show you how this is possible.

Impact:
Make your applications responsive.

Solution:
The .NET framework way back since version 1.0 introduced an asynchronous pattern which enables your code to call any synchronous method asynchronously. Things required to make this happen
  1. IAsyncResult class
  2. Begin<SynchronousMethodName>
  3. End<SynchronousMethodName 
Solution: (Adapted from Essential Windows Communication Foundations, Highly recommend to get this book)
namespace Client
{
    class Program
    {
        static int c = 0;
        static void Main(string[] args)
        {
            ServiceReference1.StockServiceClient proxy = new ServiceReference1.StockServiceClient();
            //First call it synchronously
            double price = proxy.GetPrice("msft");
            Console.WriteLine("{0} Sync price lookup:{1}", System.DateTime.Now, price);

            //Then call it 10 times asynchrnonously
            for (int i = 0; i < 10; i++)
            {
                Interlocked.Increment(ref c);
                proxy.BeginGetPrice("msft", PriceCallback, proxy);
            }
            while (c > 0)
            {
                Thread.Sleep(1000);
            }
            proxy.Close();
            Console.WriteLine("Done!");
        }

        // Asynchronous callbacks for displaying results.
        static void PriceCallback(IAsyncResult ar)
        {
            double price = ((ServiceReference1.StockServiceClient)ar.AsyncState).EndGetPrice(ar);
            Console.WriteLine("{0} Asynchronous price lookup:{1}", System.DateTime.Now, price);
            Interlocked.Decrement(ref c);
        }
    }
}

As you can see in the code above the service contains GetPrice() method that the client uses to invoke through the proxy object.  But guess when you can invoke this method Asynchronously without using a single line of threading code in either the client or server code. To do that, first

Go back to your Service Reference, right click it and Update Service Reference and select the Generate asynchronous operations. Now this will generate the Begin<GetUpdate> and End<GetUpdate> methods that can be used to asynchronously call the synchronous GetUpdate method.... how cool is that.

What does this do?

                       proxy.BeginGetPrice("msft", PriceCallback, proxy);

First you need to pass in any parameters required by the BeginGetPrice method. You also need to pass a 
delegate (a method  that accepts an IAsync state parameter) and a State object (which is usually the proxy class itself).
The delegate is called whenever the Asynchronous operation begins. For every Begin<SynchronousMethodName> you need to call the End<SynchronousMethodName> and this is usually performed in the delegate that is called when the Asynchronous operation begins.

        ((ServiceReference1.StockServiceClient)ar.AsyncState).EndGetPrice(ar);
 Recall in the proxy.BeginGetPrice() we passed the proxy object as an argument. Withing the delegate you can call this object using the code above. And it is as simple as that. Alright it is not that simple, but give it a try the next time you need to create your own asynchronous client without working with threads.

Since I am just a student (and NOT a bright one) I am bound to make a lot of mistakes. Please let me know if you find mistakes, or if more explanation is required.


Thank You Very Much For Your Time And I Hope It Was Time Well Spent