<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ?? Silverlight調用WebService只能使用異步方式調用。所謂異步方式調用就是讓調用方法的主線程不必同步等待在這個函數調用上,從而允許主線程繼續執行它下面的代碼。 ?? Silverlight調用自定義的WebService分為四個步驟: (1)、創建自定義的WebService (2)、實現WebService (3)、在Silverlight項目中添加服務引用 (4)、使用異步方式調用WebService 下面舉例介紹: ?? 比如說在MSSQL2000中建立一個名為SilverlightDB的數據庫,里面包含一張表Product,里面有2個字段Name和Price,舉例說明字段就隨便用兩個意思意思下。 ?? 在Web.Config文件中配置數據庫連接字符串 <appSettings> ?? <add key="ConnectionString" value="Data Source=.;uid=sa;pwd=111111;Database=SilverlightDB"/> </appSettings> ?接著定義一個和Product表對應的實體類Product.cs [Serializable] ?? public class Product ?? { ?????? public string Name { get; set; } ?????? public double Price { get; set; } ?? } 再接著是添加一個Web服務,文件名為ProductService.asmx 在其中添加一個獲取產品列表的方法GetAllProduct ??????? [WebMethod] ?????? public List<Product> GetAllProduct() ?????? { ?????????? List<Product> products= new List<Product>(); ?????????? //這里是從數據庫獲取數據,方式可以是ADO.NET、LINQ to SQL或者是ADO.NET Entity Framework,以下是用最簡單的ADO.NET來實現的 ?????????? string connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]; ?????????? using (SqlConnection con = new SqlConnection(connectionString)) ?????????? { ?????????????? con.Open(); ?????????????? string strSQL = "select * from Product"; ?????????????? SqlCommand cmd = new SqlCommand(strSQL, con); ?????????????? SqlDataReader data = cmd.ExecuteReader(); ?????????????? while (data.Read()) ?????????????? { ?????????????????? Product product = new Product(); ?????????????????? product.Name = data["Name"].ToString(); ?????????????????? product.Price = double.Parse(data["Price"].ToString()); ?????????????????? products.Add(product); ?????????????? } ?????????? } ?????????? return products; ?????? } 前臺顯示頁面MainPage.xaml中添加一個ListBox用于顯示數據 <ListBox x:Name="myBooks" Margin="101,144,158,124"> ??<ListBox.ItemTemplate> ???<DataTemplate> ????<StackPanel> ?????<TextBlock Text="{Binding Name}"></TextBlock> ?????<TextBlock Text="{Binding Price}"></TextBlock> ?????<TextBlock Text="---------------------------------------------------------------"></TextBlock> ????</StackPanel> ???</DataTemplate> ??</ListBox.ItemTemplate> ?</ListBox> 在MainPage.xaml.cs文件中編寫調用WebService的代碼進行數據綁定 private void LayoutRoot_Loaded(object sender, System.Windows.RoutedEventArgs e) ?????? { ?????? ?? // TODO: Add event handler implementation here. ?????????? ProductServiceReference.ProductServiceSoapClient client = new NetworkSample.ProductServiceReference.ProductServiceSoapClient(); ?????????? //注冊調用成功事件 ?????????? client.GetAllProductCompleted += new EventHandler<NetworkSample.ProductServiceReference.GetAllProductCompletedEventArgs>(OnGetAllProductCompleted); ?????????? client.GetAllProductAsync(); ?????? } ?????? private void OnGetAllProductCompleted(object sender, NetworkSample.ProductServiceReference.GetAllProductCompletedEventArgs e) ?????? { ?????????? //檢測調用是否成功 ?????????? if (e.Error != null) ?????????? { ?????????????? return; ?????????? } ?????????? myBooks.ItemsSource = e.Result; ?????? } 至此,一個Silverlight調用自定義的WebService的案例就做好了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看