Wednesday, May 11, 2011

Tip: Proper use of the jQuery "get" function

jQuery provides a function which gets a DOM element based on the index passed in. It's important to write the correct syntax at the selector part for it to work properly. For example,

let say I have a variable named "items" that is a drop down list with several options as represented at the html code below:



This will not work
items.get(1) --> TypeError: items.get is not a function

This will work
$('option', items).get(1) --> return option with value 2

Wednesday, May 4, 2011

Tip: How to make use of WorkflowControlClient to control workflows in a workflow service

If you host your WF service in IIS probably you will need a way to suspend, terminate, abandon, etc. a workflow that is running or persisted, other than using AppFabric Dashboard. In order to use WorkflowControlClient correctly, configuration at the workflow service is important. Given the following client code that terminates a workflow:

 WorkflowControlEndpoint endpoint = new WorkflowControlEndpoint()
{
Binding = new BasicHttpBinding(),
Address = new EndpointAddress("http://localhost/WorkflowService/AbsoluteDelayService.xamlx/wce")
};
WorkflowControlClient c = new WorkflowControlClient(endpoint);
if (!String.IsNullOrEmpty(TextBox2.Text))
{
c.Terminate(new Guid(TextBox2.Text));
c.Close();
}
based on the code above, the interesting part is the EndPointAddress that ends with the “wce” word. The “wce” word is actually configured in the workflow service web.config as shown below:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
<behaviors>
<serviceBehaviors>
<behavior name="behaviour2">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
<sqlWorkflowInstanceStore connectionString="Data Source=(local)\SQL2008R2;Initial Catalog=PersistenceDatabase;Integrated Security=True;Asynchronous Processing=True;"
instanceEncodingOption="GZip" instanceCompletionAction="DeleteAll" instanceLockedExceptionAction="BasicRetry" runnableInstancesDetectionPeriod="00:00:05" hostLockRenewalPeriod="00:00:05" />
<workflowInstanceManagement authorizedWindowsGroup="AS_Administrators" />
<workflowUnhandledException action="Terminate" />
<workflowIdle timeToPersist="00:01:00" timeToUnload="00:00:00" />
<etwTracking profileName="Sample Tracking Profile" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="httpSecurityOff" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MustMatchWithXamlxConfigurationName" behaviorConfiguration="behaviour2">
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
<endpoint address="wce" contract="System.ServiceModel.Activities.IWorkflowInstanceManagement" binding="basicHttpBinding" bindingConfiguration="httpSecurityOff" kind="workflowControlEndpoint" />
<endpoint address="" contract="IService" binding="basicHttpBinding" bindingConfiguration="httpSecurityOff" />
</service>
</services>
</system.serviceModel>

The configuration above shows how the service endpoints should be configured in order for client to access it through the WorkflowControlClient API. Another important thing that one must ensure is that the service name must be the same as the “ConfigurationName” in the Xamlx file.

Capture


If the name is not matching, WCF will throw exception stating the following message:



The message with To 'http://(macinename)/WorkflowService/AbsoluteDelayService.xamlx/wce cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.

Thursday, April 21, 2011

Tip: How to create a One-Way WCF WF service that persist to a SQL server?

Based on the research that i have done recently on the Workflow service using WCF, any call to a time-based workflow that has a delay activity will block the caller until the delay activity and subsequent activity is finished. That's to say, a web request is blocked until the entire workflow finish running, say for 1 minute if the delay activity is set to 1 minute. This is not the service behavior that I wanted, instead I want the service call to return immediatly after hitting the delay activity and the workflow is persisted to the database.

This how one can create a one-way WCF call to the Workflow Service:
1. Create a WCF Service Activity in Visual Studio
2. Remove the ReplyRequest Messaging activity.
3. Click on the ReceiveRequest activity, remove the item from CorrelationIntializers. This is not needed for one-way communication.
4. The end result will look something like this

5. At the client side reference the Workflow Service. Right click on the service reference and click Configure Service. Check the Generate asynchronous operations check box.

6. One can make use of the referenced service as follow:

7. Make sure to call to the GetDataAsync function and close the connection when done. The request will return immediately after the workflow hits the delay activity.
The IIS will resume whatever that is persisted in the database automatically when the time is right.

Friday, March 25, 2011

Tip: JavaScript "unload" event myth for IE8

I came across the needs to save certain state to the web server using Ajax when a user navigates away from a page, so i tried to use the browser (IE8) "unload" event to do it.
One thing that i noticed when using the "unload" event is that, once the user clicks on a new link to navigate to a new page, browser will first send the request to web server causing the "pageLoad" function to be triggered then only the Ajax request is process in the web server.
If the next page that the user navigates to relies on the first page state, there will be problem because the new page is loading without getting the data from previous page.

My workaround is not to rely on the "unload" event, but to use user action to save the state. For example, when the user clicks on a link to do popup, after the popup immediately save the state to server. It's costly but working for now.

Wednesday, March 2, 2011

Tip: Asp.Net Request.InputStream is empty?

Recently I needed to post some json data from browser to web server. I used the following codes to read the input stream:

System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
string json = sr.ReadToEnd();

There's one problem with the above codes, that is the json variable will hold empty string even though I am sure that data is posted to the web server. The resolution of the problem is to always set the stream position to 0. The resulting codes looks like this:

Request.InputStream.Position = 0; System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
string json = sr.ReadToEnd();

Now with the first line of the codes, you will be able to get the stream data.

Wednesday, January 5, 2011

Tip: Choosing MS SQL Server + Reporting Tool

Many times developers come across the need to choose which MS SQL server to use in his develoment work. Microsoft provided many different editions of the SQL server and each with different technical specification. It's wise to study through the specifications before deciding which edition of the server to deploy for end product. Here's some links that are useful for reference:

1. SQL Server 2008 R2 Editions Feature Comparison
http://technet.microsoft.com/en-us/library/cc645993(printer).aspx
2. Browser Support for SQL Server 2008 R2 Reporting Server Browser Compatibility Check
http://www.blogger.com/post-create.g?blogID=146115522879877832
3. SQL Server 2008 R2 Express Edition Reporting Service Features Summary
http://technet.microsoft.com/en-us/library/cc281020.aspx

Tuesday, August 24, 2010

Microsoft Internet Explorer 8 Not Meeting Expectation

I have been using Internet Explorer 8 for a while even before I upgraded my OS to Windows 7. When talk about browser performance I can say that IE is still not the best around. When many tabs are opened, the browser tends to act sluggishly and consuming high CPU and memory. I tried to disable all of the IE add ons but still it does not help much. The most serious case that i ever met is when i visit pages that contain complex strucutre and animation, IE is like totally dead after a while. For example, a page that contains a long table with many records and when records are updated periodically, IE sucks. If i am to compare with other browser such as FireFox 3, the performance of the FireFox is much better than IE in many ways. CPU usage and memory consumption is one noticable difference if compared to IE when browsing through heavy pages. Page scrolling of FireFox is much smoother than IE for long list of table.

Summary, the way that IE8 is built really give a big hit to online businesses that provide highly sophitiscated functions and UI, users are just requesting more and more but there is nothing much can be done or rather the limit is caused by how IE perform eventually. I hope IE 9 will give something that the users are expecting (i.e. speed + stability).