建立REST SOE的schema

孫群發表於2013-01-26

方法CreateRestSchema()對於建立REST SOE是很重要的。在這個方法中,你將為你的服務建立schema,表明SOE支援哪些資源與操作。

a.對於每個資源,你將定義一個RestResource。

b.對於每個操作,你將定義一個RestOperation。

一旦你定義了所有的資源與操作,呼叫資源和操作的 Add()方法以便建立schema。

[C#]

private RestResource CreateRestSchema()
{
    RestResource rootRes = new RestResource(soe_name, false, RootResHandler);
    RestOperation sampleOper = new RestOperation("sampleOperation", new string[]
    {
        "parm1", "parm2"
    }
    , new string[]
    {
        "json"
    }
    , SampleOperHandler);
    rootRes.operations.Add(sampleOper);
    return rootRes;
}

[VB.NET]

Private Function CreateRestSchema() As RestResource
    Dim rootRes As New RestResource("RestSOE1", False, AddressOf RootResHandler)
    Dim sampleOper As New RestOperation("sampleOperation", New String() {"parm1", "parm2"}, New String() {"json"}, AddressOf SampleOperHandler)
    rootRes.operations.Add(sampleOper)
    Return rootRes
End Function

在上面的schema中,你獲得了一個資源rootRes。該資源中包含一個操作sampleOper。

當你建立一個RestResource或一個RestOperation的時候,你可以傳遞一個可選引數capabilities名稱。capabilities是一組資源和操作,這樣伺服器管理員可以方便的統一管理該組資源和操作啟用或者不啟用。

需要注意的是,當你在ArcCatalog中開啟服務編輯對話方塊或在Manager中編輯服務的時候,capabilities會顯示為“允許的操作”字樣。

不要將SOE的capabilities和對話方塊中可進行勾選的"Capabilities"進行混淆。對話方塊中的“Capabilities”指的是SOEs本身。

模板中的程式碼沒有定義任何的capabilities,但是你可以在REST示例Find Near Features中檢視如何使用capabilities。

建立一個schema就像搭積木直到你建立了最終的高樓大廈。首先從schema中最深層次開始,為每一層級新增資源和操作,如此繼續,直到根級別,這樣你就建立了一個完整的schema。這一過程在模板中沒有展現出來,因為模板程式碼僅僅展示了一個資源和操作被建立的過程。不過你會在SDK的示例中檢視更復雜的schema的建立過程。

相關文章