承接上篇 AppFabric 介紹,本文實作 Pizza 訂購系統,示範將 WCF Workflow Service 部署至 AppFabric,並配置 SQL 持久化與自訂追蹤。
[DataContract(Namespace="urn:pizzas")]
public class PriceResponse
{
[DataMember] public int OrderId { get; set; }
[DataMember] public double Price { get; set; }
}
protected void Button1_Click(object sender, EventArgs e)
{
var client = new FeedMeClient("BasicHttpBinding_IFeedMe");
var prse = client.GetPizzaCost(DropDownList1.Text, int.Parse(TextBox1.Text));
ViewState["id"] = prse.OrderId;
Label1.Text = $"訂單號碼:{prse.OrderId} 價格:{prse.Price}";
client.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["id"] != null)
{
var client = new FeedMeClient("BasicHttpBinding_IFeedMe");
Label1.Text = client.ConfirmOrder(int.Parse(ViewState["id"].ToString()));
client.Close();
}
}
<trackingProfile name="CustomServiceProfile">
<workflow activityDefinitionId="*">
<workflowInstanceQueries>
<workflowInstanceQuery><states><state name="*"/></states></workflowInstanceQuery>
</workflowInstanceQueries>
<activityStateQueries>
<activityStateQuery activityName="GetPizzaCost">
<states><state name="Closed"/></states>
<variables><variable name="quantity"/><variable name="type"/></variables>
</activityStateQuery>
</activityStateQueries>
<faultPropagationQueries><faultPropagationQuery faultSourceActivityName="*" faultHandlerActivityName="*"/></faultPropagationQueries>
<bookmarkResumptionQueries><bookmarkResumptionQuery name="*"/></bookmarkResumptionQueries>
<customTrackingQueries><customTrackingQuery name="*" activityName="*"/></customTrackingQueries>
</workflow>
</trackingProfile>
透過 AppFabrit 管理介面可監控實例執行狀態、檢視追蹤記錄,實現生產級 WF 服務營運。