SQL Server Data Services (SSDS) 是微軟早期雲端資料服務嘗試 (後演變為 SQL Azure / Azure SQL Database)。本文基於預發布版本,介紹 SSDS 資料模型、實體/容器/授權機構管理、示範 Web 應用開發、類別序列化與自定義結構描述。注意:文中資訊可能已過時,僅供架構演進參考。
POST /{authority} HTTP/1.1
Content-Type: application/ssds+xml
Authorization: SharedKey {account}:{signature}
MyAuthority
POST /{authority}/{container} HTTP/1.1
...
Products
Flexible
-- 建立/更新實體 (Upsert)
PUT /{authority}/{container}/{entityId} HTTP/1.1
Content-Type: application/ssds+xml
If-Match: "{version}" -- 樂觀鎖
SKU12345
1
Product
Widget Pro
29.99
hot;sale;new
-- 查詢實體
GET /{authority}/{container}?query=Kind:Product AND Price>20 HTTP/1.1
-- 刪除實體
DELETE /{authority}/{container}/{entityId} HTTP/1.1
If-Match: "{version}"
| 業務概念 | SSDS 映射 | Kind 值 |
|---|---|---|
| 城市 | Container: Cities / Entity | City |
| 類別 | Container: Categories / Entity | Category |
| 廣告列表 | Container: Listings / Entity | Listing |
| 自定義結構描述 | Container 中繼資料 | Schema |
public class SsdsClient {
private readonly string _authority, _account, _key;
private readonly HttpClient _http;
public async Task UpsertEntityAsync(string container, Entity entity) {
var xml = entity.ToSsdsXml();
var req = new HttpRequestMessage(HttpMethod.Put,
$"{_baseUrl}/{_authority}/{container}/{entity.Id}") {
Content = new StringContent(xml, Encoding.UTF8, "application/ssds+xml")
};
req.Headers.Add("If-Match", $"\"{entity.Version}\"");
SignRequest(req);
var resp = await _http.SendAsync(req);
resp.EnsureSuccessStatusCode();
return Entity.FromSsdsXml(await resp.Content.ReadAsStringAsync());
}
public async Task> QueryAsync(string container, string query) {
var resp = await _http.GetAsync($"{_baseUrl}/{_authority}/{container}?query={Uri.EscapeDataString(query)}");
return Entity.ParseFeed(await resp.Content.ReadAsStringAsync());
}
}
// 實體類別序列化/反序列化
[DataContract]
public class Entity {
[DataMember(Name="Id")] public string Id { get; set; }
[DataMember(Name="Version")] public string Version { get; set; }
[DataMember(Name="Kind")] public string Kind { get; set; }
[DataMember(Name="Properties")] public List Properties { get; set; }
public string ToSsdsXml() { /* XML 序列化邏輯 */ }
public static Entity FromSsdsXml(string xml) { /* XML 反序列化邏輯 */ }
}
Listings
Explicit
public class ListingEntity : Entity {
public ListingEntity() { Kind = "Listing"; }
[EntityProperty("Title")] public string Title { get; set; }
[EntityProperty("Price")] public decimal Price { get; set; }
[EntityProperty("PostedDate")] public DateTime PostedDate { get; set; }
[EntityProperty("Images", MultiValued=true)] public List Images { get; set; }
// 自動映射屬性 <-> SSDS Properties
}
| SSDS 概念 | Azure SQL Database / Cosmos DB 對應 |
|---|---|
| Authority | Azure 訂閱 / Cosmos DB 帳戶 |
| Container | SQL Database / Cosmos DB 容器 |
| Entity (Flexible) | Cosmos DB 項目 (JSON 文檔) |
| Entity (Explicit) | SQL Database 資料表列 |
| REST + XML | TDS / REST + JSON (Cosmos) / GraphQL |
| 自定義結構描述 | SQL DDL / Cosmos DB 索引原則 |
SSDS 雖已退役,但其核心思想——多租戶隔離、半結構化實體、RESTful 介面、樂觀並發、彈性結構描述——深刻影響了後續 Azure 資料服務架構。理解 SSDS 有助於把握雲端原生資料平台的設計基因。