Thursday, January 3, 2008

JBOSS for .Net Issue (505)

JBOSS has known issue when talking to .NET Client.

You will receive this error.
The request failed with HTTP status 505: HTTP Version Not Supported.


This error happened because .NET does not implement HTTP 1.1 properly (specifically contiuations), therefore the only way you can fix this is to force the client to use HTTP 1.0.

You can enable in on Server Side / Client side.

On Server Side:
adding the following option (in bold) to your http connector tag in your tomcat server.xml file.
Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="8443" acceptCount="100"
restrictedUserAgents="^.*MS Web Services Client Protocol.*$"
connectionTimeout="20000" disableUploadTimeout="true"

On Client Side:
Change .NET webservice to use HTTP 1.0 by adding the following code to your proxy class.
 protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest httpReq = (HttpWebRequest)base.GetWebRequest(uri);
httpReq.ProtocolVersion = System.Net.HttpVersion.Version10;
return httpReq;
}


Debugging into System Code

I just find that we can not debug into system generated code because by default "Just My Code" is enabled.....

To be able to debug a system generated code such as proxy/wsdl... you need to disable "Just My Code" inside debugging options.

Steps:
* Tool>Options>Debugging>General
* Untick Enable Just My Code (Managed Only)....

Sunday, December 30, 2007

Enhance Data View Performance using Asynchronous Method

Currently I find a way how to enhance a performance to view 10.000 records which taken from Web service layer.

First of all, I can not using any caching because this data will change very often.
Every time the user change something, I need to refresh the data.

I can not use Sql Dependency because all the data are encapsulate on service layer.
I can not perform paging on service layer because it is not provided to me.


Finally, the only way is using Asynchronous Method.

The idea is to display the first page of the records and start retrieving others data asynchronously.

The next time the user want to perform, sorting, filtering or paging, It will force to finish all retreiving data.

This algorithm will force using user thinking time in retreiving huge records rather than forcing user to wait retrieving huge records every time even they just want to see the first page records.

Here is the Algorithm:
=================================
If ( ! IsPostback)
{
* Clear Data set from session
* Retrieve 1st page only and bind to data grid with next/previous paging style
* Create a delegate to retrieve the rest of data
* Start asynchronous call with BeginInvoke.
* Store that delegate and IAsynResult into session.
}
else
{ //( Postback) and user try to bind a data (Sorting, Paging, Filtering)
If (There still no data set in Session)
{
* Take delegate and IAsynResult
* Force delegate to finish by using EndInvoke(IAsynResult)
* Store the data set into Session.
* Bind to data grid with default paging style.
}
else
{
* directly use data set from session and bind to data grid with default paging style.
}
}
===============================

Note:
You may optimize this algorithm by getting a number of record first.
If the number of records is less or equal then the number of first page records, just store that data into session and bind it to data grid with default paging style.
You don't need to perform asynchronous call for this.


The only weakness of this methodology is it will be more thread in your application.

Sunday, December 16, 2007

Notify your custom application from CRM 3.0

This is one of the solution how you notify your application from Microsoft Dynamic CRM 3.0

1. Add Javascripts to notify your application from CRM Custom forms.
a. Open CRM 3.0

b. Go To Settings/ Customization

c. Select what entity you need ( Example phone, email, ...)

d. Go to forms and view on the left tab after you open your entity

e. Select the forms you want to add the scripts.

f. click add properties.

g. There is 2 available event handler (OnSave and OnLoad)

h. Put your javascript there
for example : window.opener('Notify on save');

i. Don't forget to check enable this event before you save it.

j. You may preview it before publish the changes.

g. Don't forget to publish - Action/Publish.

If you forget to publish, It will not take any changes you have made, even you have save it.

Friday, December 14, 2007

Better way to handle thread abort exception in Response.Redirect

private bool m_bIsTerminating = false;

protected void Page_Load(object sender, EventArgs e)
{
if (WeNeedToRedirect == true)
{
Response.Redirect(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
m_bIsTerminating = true;
// remember to end the method here if
// there is more code in it

return;
}
}

protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
if (m_bIsTerminating == false)
base.RaisePostBackEvent(sourceControl, eventArgument);
}

protected override void Render(HtmlTextWriter writer)
{
if (m_bIsTerminating == false)
base.Render(writer);
}

Friday, November 16, 2007

Datagrid VS ViewState

This week, I try to optimized my web application which using 10 million record.

The first thing that I notice that EnableViewState by default is set to true.

So my datagrid will store all the view state into client. so every time there is postback or asyn postback, it will transfer heaps of data through networks. and It is not very efficient.

So I try to disable them by EnablingViewState = false.
However by disabling view state in the data , all the events in datagrid is not fired..


one of the solution is to disable view state on each item.
_dg.DataBind();
foreach (DataGridItem item in _dg.Items)
{
item.EnableViewState=false;
{


however, if your all commandArguments is not work,..

so the other solution is you need to bind every time in page back...

Tuesday, November 6, 2007

Resurrection

Just in case if you don't know.

Sometimes it is you may need to resurrects your object.
for example you want the object to clean itself gracefully everytime the object dies.

Here how to do resurrection....

public class MyBaseClass
{
Protected override void Finalize()
{
//TODO: Some Clean up....

GC.ReRegisterForFinalize(this);
}
}

By calling GC.ReRegisterForFinalize method, it will appends the address of the specified object to the end of the finalization queue. When GC detects that this object is unreadchable again, It will queue the object's pointer ob the freachable queue and Finalize method will get called again.

This is example show how to create an object that constantly resurrects itself and never dies...
which usually undesireable. It is far more common to conditionally set a root to a reference the object inside the finalize method.