WCF服務呼叫Mysql資料庫簡單例項

2021-08-25 08:22:31 字數 2004 閱讀 2691

準備資料

create database saleslibrary ---建立資料庫

create table `salesvolume` ( ---建立表

`id` int(11) default null,

`num` int(11) default null,

`product` varchar(20) default null)

insert into `salesvolume` values ('13', '1789', '賓士'); ---插入資料

insert into `salesvolume` values ('14', '1843', '寶馬');

insert into `salesvolume` values ('15', '1540', '奧迪');

在專案中引用 mysql.data.dll

在操作類當中新增:

using mysql.data

;using mysql.data

.mysqlclient

;

1.建立乙個wcf解決方案

2. 新增mysql.data.dll引用

3. 刪除「iservice1.cs」「service1.svc」

4. 新增自己的wcf服務

}mysqlinfo.svc(此處使用的mysqldataadapter ,返回datatable供winform使用)

using system.data;

using mysql.data;

using mysql.data.mysqlclient;

namespace firstwcfservice

public datatable getsalesvolume()

catch (mysqlexception ex)

finally}}

}}

2.啟動專案,檢視測試結果(也可以複製url路徑,在web瀏覽器上檢視)

此時伺服器端的相關操作可以告一段落。

建立winform測試專案,使用gridcontrol顯示呼叫的資料(呼叫gridcontrol需要安裝devexpress外掛程式,自行上網查詢)

form1的頁面布局

4.顯示結果

ajax呼叫WCF服務

關於ajax呼叫wcf服務分為跨域和不跨域兩種方式,今天咱們先介紹下不跨域下的呼叫方法。demo是在vs2008寫的.經過測試與研究,發現ajax呼叫wcf服務必須滿足以下條件 1.wcf的通訊方式必須使用webhttpbinding 2.必須設定節點的值 3.服務的實現必須新增 aspnetcom...

動態呼叫WCF服務

動態呼叫wcf服務,只需要提供 svc位址,1 命名空間 using system.servicemodel.channels using system.servicemodel 2 建立訪問類invokecontext public class invokecontext public stati...

動態呼叫WCF服務

前言 由於wcf發布後,伺服器位址隨時變化,引用服務的程式就需要改變引用url才可訪問,此文記載動態呼叫wcf服務 1 發布wcf參考前文 2 新建一winform程式,新增引用system.servicemodel 3 使用工具svcutil.exe工具,工具位置c program files x...