元数据导入

WWSAPI 包括可用于从终结点处理 WSDL 和 Policy 的 API 元素,目的是提取可用于与终结点通信的信息。 当终结点支持的通信协议尚未知时,通常会使用这些 API。

使用以下序列处理元数据:

WsCreateMetadata    // create a metadata object

while there are metadata documents to add
{
    // retrieve the metadata document from it's location
    // (download, read from file, etc)

    // add the document to the metadata object
    WsReadMetadata

    // optionally query the metadata object for any missing documents
    WsGetMissingMetadataDocumentAddress?
}

// get the endpoints from the metadata object
WsGetMetadataEndpoints

for each endpoint
{            
    // examine the endpoint information to see if 
    // the endpoint is relevant for the particular scenario

    if the endpoint is relevant
    {
        // get the policy object from the endpoint

        // get the number of policy alternatives in the policy
        WsGetPolicyAlternativeCount

        for each policy alternative
        {
            // construct a policy constraints structure that specifies
            // what policy is acceptable and what information to extract
            // from the policy

            // see if the policy alternative matches the constraints
            WsMatchPolicyAlternative

            // if there is a match, then use it

            // if there is not a match, then it is also possible to 
            // try with a different constraint structure
        }
    }
}

// If reusing the metadata object for a different set of documents
WsResetMetadata? // reset metadata object, which removes all documents

WsFreeMetadata // free the metadata object

有关 WSDL 和 WS-Policy 断言如何与 API 相对应的信息,请参阅 元数据映射 主题。

安全

下载的元数据仅与用于下载它的地址一样好。 应用程序应确保信任该地址。 此外,应用程序应确保它使用安全协议下载不允许篡改元数据的元数据文档。

应用程序应检查元数据公开的服务的地址。 默认情况下,运行时可确保服务的主机名与用于下载元数据的原始 URL 的主机名匹配,但应用程序可能需要执行其他检查。 应用程序可以通过覆盖 WS_METADATA_PROPERTY_VERIFY_HOST_NAMES 属性来禁用主机名验证。 如果默认禁用的主机名检查已禁用,则应用程序需要保护自身免受包含服务地址的元数据文档的保护,而该客户端不以其他方式信任该服务的地址。

默认情况下,元数据运行时用于反序列化和处理元数据的最大内存量为 256k,可添加的最大文档数为 32。 可以通过 WS_METADATA_PROPERTY_HEAP_REQUESTED_SIZEWS_METADATA_PROPERTY_MAX_DOCUMENTS 属性覆盖这些默认值。 这些边界旨在限制下载量,并限制分配的内存量,以便累积元数据。 增加这些值可能会导致内存使用率、CPU 使用率或网络带宽消耗过多。 请注意,由于二进制格式的字典字符串的扩展,小消息可能会导致一个更大的反序列化形式,因此在使用二进制格式时,依赖小消息来限制元数据内存分配是不够的。

默认情况下,策略替代项的最大数目为 32,但可以通过 WS_POLICY_PROPERTY_MAX_ALTERNATIVES 属性覆盖它。 如果应用程序循环访问每个查找匹配项的替代项,则可能需要先搜索所有替代项,然后再查找匹配项。 增加最大替代项数可能会导致 CPU 使用率过高。

以下枚举是元数据导入的一部分:

以下函数是元数据导入的一部分:

以下句柄是元数据导入的一部分:

以下结构是元数据导入的一部分: