2

我正在使用 gSOAP 从 WSDL 文档创建 C++ 代码。问题是当我在我的 WSDL 文件上运行 wsdl2h 工具时,gSOAP 给了我错误。这些错误都与命名空间问题有关。例如

Warning: could not find element 'GetRPCMethods' type '"http://www.broadband-forum.org/cwmp/cwmp-1-2.xsd":GetRPCMethods' in schema urn:tr069

我在下面粘贴了命名空间定义和如何使用它们的示例。有人知道我哪里出错了吗?

urn:tr069 应该是指当前文档。

<s0:definitions 
    name="tr069"
    xmlns:s0="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:s1="urn:tr069"
    xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/"
    targetNamespace="urn:tr069">

<s0:types>

<xsd:schema 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:tns="urn:tr069" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd1="http://www.broadband-forum.org/cwmp/cwmp-1-2.xsd"
    targetNamespace="urn:tr069">

  <xsd:import namespace="urn:dslforum-org:cwmp-1-2" schemaLocation="cwmp-1-2.xsd" />
  <xsd:element name="GetRPCMethods" type="xsd1:GetRPCMethods" />
</xsd:schema>
</s0:types>
<s0:message name="GetRPCMethods">
     <s0:part element="s1:GetRPCMethods" name="GetRPCMethods" />
</s0:message>
</s0:definitions>

我还有一些其他问题,据我了解,目标命名空间不必指向真实位置,它只是指向当前文档的约定,这是正确的吗?同样在 cwmp-1-2.xsd 中有一个名为 GetRPCMethods 的元素,它包含一个包含另一个元素的序列。使用整个元素(GetRPCMethods)作为我上面的消息的一部分是最佳实践,还是应该在消息中定义 GetRPCMethods 的特定部分?

谢谢你。

4

3 回答 3

3

问题是<schema>标签中定义的元素。首先,我删除了<schema>标签内所有定义的元素,因为无论如何它们都是完全不必要的。然后我将消息部分中元素的命名空间从 s1 更改为 xsd1 以使用 cwmp-1-2.xsd 中的元素而不是我在<schema>标记中定义的元素。

至于我的其他问题,targetNameSpace 不必指向真正的 uri,它只是该文档的命名空间的名称。对于我的第二个问题,我认为使用整个架构元素作为消息的一部分可能是最好和最简单的。

于 2011-03-02T12:55:21.757 回答
0

我注意到

<xsd:schema>

没有结束标签?wsdl 是格式良好的 XML 文档吗?

Targetnamespace 是实例文档的名称空间,即 SOAP:Envelope 的名称空间。

于 2011-03-01T16:12:51.303 回答
0

错误消息说出了什么问题,您没有定义 xsd1:GetRPCMethods,这是在某个地方定义的吗?查找 s1:GetRPCMethods -> 发现 s1 是 urn:trn069 -> urn:trn069 不是唯一的,这可能是一个问题 -> urn:trn69 定义元素 GetRPCMethods,其类型为 xsd1:GetRPCMethods -> 此类型没有找到。

我不确定对 targetNamespace 使用相同的 URI 是否有效。也许这会导致其他问题。

于 2011-03-01T16:40:46.090 回答