WF4.0實戰(二十一):Windows Server AppFabric中宿主WF4.0應用程式

來源:互聯網
上載者:User

    在之前的一篇博文Windows Server AppFabric介紹上,簡單的介紹了一下Windows Server AppFabric。這篇文章中,我將介紹一下,如何在將WF4.0應用程式宿主到Windows Server AppFabric中,以及如何持久化配置和追蹤配置。

    首先,我將使用asp.net和WF4.0實現一個簡單的Pizza訂購系統。然後將這個應用系統宿主到Windows Server AppFabric上,實現持久化,跟蹤等配置。

    Pizza訂購系統:

    分兩部分,一個是asp.net應用程式實現UI介面;另外一個是WF Service實現商務邏輯,系統類別似。

   實現WF Service:

   業務處理過程是:客戶在asp.net用戶端選擇Pizza類型和填寫Pizza的數量,然後提交給WF Service處理。WF Service根據選擇的Pizza類型查詢出價格,然後計算Pizza的總價格,並將這個價格返回給asp.net用戶端。然後購買者確認是否訂購,確認之後,WF Service報告對應的資訊。這個流程我分成了兩個部分。

    第一部分如:擷取Pizza的價格。

    第二部分是:確認訂購,如:

    用戶端和服務端互動的資料實體代碼如下;

    [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)        {            FeedMeClient client = new FeedMeClient("BasicHttpBinding_IFeedMe");            PriceResponse prse = client.GetPizzaCost(DropDownList1.Text, int.Parse(TextBox1.Text));            ViewState["id"] = prse.OrderId;            Label1.Text = "訂單號碼為:" + prse.OrderId + "價格為" + prse.Price.ToString();            client.Close();        }        protected void Button2_Click(object sender, EventArgs e)        {           if(ViewState["id"]!=null)           {               FeedMeClient client = new FeedMeClient("BasicHttpBinding_IFeedMe");               Label1.Text = client.ConfirmOrder(int.Parse(ViewState["id"].ToString()));               client.Close();           }        }

如何將這個應用程式宿主到Windows Server AppFabric。

首先:要安裝Windows Server AppFabric,安裝的順序見Windows Server AppFabric介紹。

第二步:產生WCF的zip包,選擇服務項目,右鍵選擇build deplyment packpage。在\obj\Debug\Package路徑下面可以看到產生的zip檔案,如:

第三步:開啟IIS,建立一個網站,命名為:RichsPizzaService,連接埠改為90,如:

第四步:選擇部署,如

第五步:選擇包,然後一直點下一步,直到完成。

第六步:配置持久化:選擇服務,右鍵配置,如:

配置工作流程暫留:

配置工作流程主機管理:

第七步:配置跟蹤:

1、在\obj\Debug\Package中建立一文字檔,輸入下面文本,將其尾碼改成tp。

<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>

2、配置監控:在下面介面中選擇上面建立的tp檔案,點擊確認。

 

效果:

1、在aspx頁面上選擇,一種pizza,輸入你要的數量,如:

2、點擊提交,獲得pizza的總價格,如:

3、點擊確認,pizza店會告訴你,你的pizza已經在路上了,你等著就行了。

4、Windows Server AppFabric上進行查看:

告訴你,已經有7次pizza的預定了。

選擇一個執行個體,查看跟蹤資訊:

 

你將會看到如下的事件資訊:

這個應用程式很簡單,就不能看持久化的效果了。

總結:這篇文章教你如何在Windows Server AppFabric上發布和使用WF4.0應用程式,如何配置Windows Server AppFabric。

附件:pizza訂購系統代碼http://files.cnblogs.com/zhuqil/WFServices.rar

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.