使用PHP來處理Silverlight (SOAP) (下)

這一篇將介紹如何讓Silverlight在事件觸發之後傳輸資料給PHP的SOAP web service.

STEP1: 在VS2010的Silverlight專案按右鍵 > Add Service Reference

step3

STEP2: 確認你的wsdl 已經上傳到web server上之後, 將他的路徑輸入在 “Address”的欄位之中. 並按下 “Go”, 就可以看到ageService的SOAP出現在Services的欄位中.

此外, 為了方便起見, 我們也將Namespace命名程成 “AgeService” (這名字將會在xaml.cs中再度用到)

step4

Step3 : 按下OK之後就會發現專案檔中出現兩個新的檔案, 一個是AgeService, 另一個是config檔. 雙擊config檔.

step5

Step4: 你會發現剛剛設定的東西已經被記錄到Config檔裡面去了.

step6

STEP5: 接下來是處理XAML.CS中的事件, 其中包含了兩個function的CODE:

namespace SilverlightApplication2
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            AgeService.ageServicePortTypeClient client = new AgeService.ageServicePortTypeClient();
            client.getAgeCompleted += new EventHandler(client_getAgeCompleted);
            client.getAgeAsync(txtName.Text);
            HtmlPage.Window.Alert(txtName.Text);
        }

        void client_getAgeCompleted(object sender, SilverlightApplication2.AgeService.getAgeCompletedEventArgs e)
        {
            HtmlPage.Window.Alert(e.Result.ToString());
        }
    }
}

STEP6: 將Silverlight Application再BUILD一次, 並將新的XAP檔上傳到遠端主機上.

STEP7: 再RUN一次index.php, 並輸入關鍵字 “alfie” 則輸出”27″, 這樣就大功告成了!
last

檔案之間的對照表:
comparison

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *