4

我正在使用 SDL Tridion 2011 SP1 中的核心服务创建架构。在创建 Schema 时,我使用了 Schema 的自定义命名空间 URI。一般我们直接通过 Tridion CME 创建 Schema 时,会得到一个自动生成的命名空间 URI,以uuid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

我已经使用此代码创建了一个模式:

Tridion.ContentManager.CoreService.Client.SchemaData schemas = new SchemaData
{
    Title = "coreservicesschema3",
    Description = "coreservicesschema",
    Id = "tcm:0-0-0",
    LocationInfo = new LocationInfo
    {
        OrganizationalItem =
            new LinkToOrganizationalItemData { IdRef = "tcm:7-18-2" }
    },

    RootElementName = "Content",
    NamespaceUri = "customnamespaceuri",
    Xsd = xsd.ToString(SaveOptions.None)
};
schemas = (SchemaData)client.Create(schemas, new ReadOptions());
Response.Write("<BR>" +"new schema id"+ schemas.Id);
Response.Write("<BR>" + "new schema Name" + schemas.Title);
//schema created

谁能指出如何使用默认命名空间 URI 创建模式?

谢谢

4

1 回答 1

6

使用核心服务创建 Schema 所需的最少代码如下:

using (var client = new SessionAwareCoreServiceClient(netTcpBinding, remoteAddress))
{
    SchemaData schemaData = client.GetDefaultData(ItemType.Schema, folderId) as SchemaData;
    schemaData.Description = "description";
    schemaData = client.Save(schemaData, readOptions) as SchemaData;
    schemaData = client.CheckIn(schemaData.Id, readOptions) as SchemaData;

    Console.WriteLine("Schema: " + schemaData.LocationInfo.WebDavUrl);
}

Schema 将使用默认命名空间创建。在此示例中,它也不包含任何字段,但这不是您所要求的。

于 2012-04-09T05:32:08.843 回答