在WCF傳遞DataSet

抓取資料如下:

image

WCF Binding 設定如下

image

WCF 服務程式如下:

Public Function GetCustomers(ByVal strCustID() As String) As DataSet Implements IService1.GetDataset
    Dim strCust As String = "SELECT * FROM Customers WHERE CustomerID IN(‘" & Join(strCustID, "’,’") & "’)"
    Dim adp As New SqlDataAdapter(strCust, "Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=P@ssw0rd")
    Dim ds As New DataSet
    adp.Fill(ds)
    Return ds
End Function

Public Function GetCustomersBin(ByVal strCustID() As String) As DataSet Implements IService1.GetDatasetBin
    Dim strCust As String = "SELECT * FROM Customers WHERE CustomerID IN(‘" & Join(strCustID, "’,’") & "’)"
    Dim adp As New SqlDataAdapter(strCust, "Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=P@ssw0rd")
    Dim ds As New DataSet
    adp.Fill(ds)
    ds.RemotingFormat = SerializationFormat.Binary
    Return ds
End Function

WCF 提供服務,設定Binding為netTcpBinding,就抓取的封包顯示,傳遞DataSet時序列化似乎會自動採用其RemotingFormat屬性是SerializationFormat.Binary,不需額外的設定。

image

若Binding採用wsHttpBinding,就算DataSet的RemotingFormat屬性採用SerializationFormat.Binary,就封包看起來,還是以XML格式序列化。

image

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: