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));
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:
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
<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" />
<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" />
<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" />

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.


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.